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