linkmap issue: no attachment; inline patch instead
[ikiwiki] / doc / bugs / linkmap_displays_underscore_escapes.mdwn
1 [[ikiwiki/directive/linkmap]]s display the file name instead of the pagetitle, showing unsightly underscore escapes and underscores instead of blanks to users.
2
3 the attached [[!taglink patch]] fixes this; from its commit message:
4
5     display the pagetitle() in linkmaps
6     
7     without this patch, linkmaps display underscores and underscore escape
8     sequences in the rendered output.
9     
10     this introduces a pageescape function, which invoces pagetitle() to get
11     rid of underscore escapes and wraps the resulting utf8 string
12     appropriately for inclusion in a dot file (using dot's html encoding
13     because it can represent the '\"' dyad properly, and because it doesn't
14     need special-casing of newlines).
15
16 everything below that line is the patch as produced by git-format-patch. (btw, what's the preferred way to send patches, apart from creating a git branch somewhere?)
17
18 --------- snap ------------<pre>
19
20 From efbb1121ffdc146f5c9a481a51f23ad151b9f240 Mon Sep 17 00:00:00 2001
21 From: chrysn <chrysn@fsfe.org>
22 Date: Thu, 15 Mar 2012 14:38:42 +0100
23 Subject: [PATCH] display the pagetitle() in linkmaps
24
25 without this patch, linkmaps display underscores and underscore escape
26 sequences in the rendered output.
27
28 this introduces a pageescape function, which invoces pagetitle() to get
29 rid of underscore escapes and wraps the resulting utf8 string
30 appropriately for inclusion in a dot file (using dot's html encoding
31 because it can represent the '\"' dyad properly, and because it doesn't
32 need special-casing of newlines).
33 ---
34  IkiWiki/Plugin/linkmap.pm |   17 +++++++++++++++--
35  1 files changed, 15 insertions(+), 2 deletions(-)
36
37 diff --git a/IkiWiki/Plugin/linkmap.pm b/IkiWiki/Plugin/linkmap.pm
38 index ac26e07..b5ef1a1 100644
39 --- a/IkiWiki/Plugin/linkmap.pm
40 +++ b/IkiWiki/Plugin/linkmap.pm
41 @@ -5,6 +5,7 @@ use warnings;
42  use strict;
43  use IkiWiki 3.00;
44  use IPC::Open2;
45 +use HTML::Entities;
46  
47  sub import {
48         hook(type => "getsetup", id => "linkmap", call => \&getsetup);
49 @@ -22,6 +23,18 @@ sub getsetup () {
50  
51  my $mapnum=0;
52  
53 +sub pageescape {
54 +       my $item = shift;
55 +       # encoding explicitly in case ikiwiki is configured to accept <> or &
56 +       # in file names
57 +       my $title = pagetitle($item, 1);
58 +       # it would not be necessary to encode *all* the html entities (<> would
59 +       # be sufficient, &" probably a good idea), as dot accepts utf8, but it
60 +       # isn't bad either
61 +       $title = encode_entities($title);
62 +       return("<$title>");
63 +}
64 +
65  sub preprocess (@) {
66         my %params=@_;
67  
68 @@ -63,7 +76,7 @@ sub preprocess (@) {
69         my $show=sub {
70                 my $item=shift;
71                 if (! $shown{$item}) {
72 -                       print OUT "\"$item\" [shape=box,href=\"$mapitems{$item}\"];\n";
73 +                       print OUT pageescape($item)." [shape=box,href=\"$mapitems{$item}\"];\n";
74                         $shown{$item}=1;
75                 }
76         };
77 @@ -74,7 +87,7 @@ sub preprocess (@) {
78                         foreach my $endpoint ($item, $link) {
79                                 $show->($endpoint);
80                         }
81 -                       print OUT "\"$item\" -> \"$link\";\n";
82 +                       print OUT pageescape($item)." -> ".pageescape($link).";\n";
83                 }
84         }
85         print OUT "}\n";
86 -- 
87 1.7.9.1