linkmap issue: linked to a similar issue
[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 the output will look much better (at least in my wikis) with the "[[bugs/pagetitle function does not respect meta titles]]" issue fixed.
17
18 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?)
19
20 --------- snap ------------<pre>
21
22 From efbb1121ffdc146f5c9a481a51f23ad151b9f240 Mon Sep 17 00:00:00 2001
23 From: chrysn <chrysn@fsfe.org>
24 Date: Thu, 15 Mar 2012 14:38:42 +0100
25 Subject: [PATCH] display the pagetitle() in linkmaps
26
27 without this patch, linkmaps display underscores and underscore escape
28 sequences in the rendered output.
29
30 this introduces a pageescape function, which invoces pagetitle() to get
31 rid of underscore escapes and wraps the resulting utf8 string
32 appropriately for inclusion in a dot file (using dot's html encoding
33 because it can represent the '\"' dyad properly, and because it doesn't
34 need special-casing of newlines).
35 ---
36  IkiWiki/Plugin/linkmap.pm |   17 +++++++++++++++--
37  1 files changed, 15 insertions(+), 2 deletions(-)
38
39 diff --git a/IkiWiki/Plugin/linkmap.pm b/IkiWiki/Plugin/linkmap.pm
40 index ac26e07..b5ef1a1 100644
41 --- a/IkiWiki/Plugin/linkmap.pm
42 +++ b/IkiWiki/Plugin/linkmap.pm
43 @@ -5,6 +5,7 @@ use warnings;
44  use strict;
45  use IkiWiki 3.00;
46  use IPC::Open2;
47 +use HTML::Entities;
48  
49  sub import {
50         hook(type => "getsetup", id => "linkmap", call => \&getsetup);
51 @@ -22,6 +23,18 @@ sub getsetup () {
52  
53  my $mapnum=0;
54  
55 +sub pageescape {
56 +       my $item = shift;
57 +       # encoding explicitly in case ikiwiki is configured to accept <> or &
58 +       # in file names
59 +       my $title = pagetitle($item, 1);
60 +       # it would not be necessary to encode *all* the html entities (<> would
61 +       # be sufficient, &" probably a good idea), as dot accepts utf8, but it
62 +       # isn't bad either
63 +       $title = encode_entities($title);
64 +       return("<$title>");
65 +}
66 +
67  sub preprocess (@) {
68         my %params=@_;
69  
70 @@ -63,7 +76,7 @@ sub preprocess (@) {
71         my $show=sub {
72                 my $item=shift;
73                 if (! $shown{$item}) {
74 -                       print OUT "\"$item\" [shape=box,href=\"$mapitems{$item}\"];\n";
75 +                       print OUT pageescape($item)." [shape=box,href=\"$mapitems{$item}\"];\n";
76                         $shown{$item}=1;
77                 }
78         };
79 @@ -74,7 +87,7 @@ sub preprocess (@) {
80                         foreach my $endpoint ($item, $link) {
81                                 $show->($endpoint);
82                         }
83 -                       print OUT "\"$item\" -> \"$link\";\n";
84 +                       print OUT pageescape($item)." -> ".pageescape($link).";\n";
85                 }
86         }
87         print OUT "}\n";
88 -- 
89 1.7.9.1