]> sipb.mit.edu Git - ikiwiki.git/blob - doc/bugs/Problem_with_toc.pm_plug-in.mdwn
a5fe6b923d9323a4d13de173e82490d9761451c9
[ikiwiki.git] / doc / bugs / Problem_with_toc.pm_plug-in.mdwn
1 The toc.pm plug-in currently renders empty 'a' tag elements. This seems to confuse at least Firefox, possibly others. The result is that the following text is rendered as an anchor (visible if you style 'a' elements in a different color).
2
3 Here is a patch for toc.pm for producing non-empty 'a' elements.
4
5     --- IkiWiki/Plugin/toc.pm.orig      Thu Jun  7 11:53:53 2007
6     +++ IkiWiki/Plugin/toc.pm   Thu Jun  7 13:00:00 2007
7     @@ -47,7 +47,7 @@ sub format (@) { #{{{
8                 if ($tagname =~ /^h(\d+)$/i) {
9                         my $level=$1;
10                         my $anchor="index".++$anchors{$level}."h$level";
11     -                   $page.="$text<a name=\"$anchor\" />";
12     +                   $page.="$text<a name=\"$anchor\">";
13         
14                         # Take the first header level seen as the topmost level,
15                         # even if there are higher levels seen later on.
16     @@ -90,6 +90,16 @@ sub format (@) { #{{{
17                                         "</a>\n";
18                                 $p->handler(text => undef);
19                         }, "dtext");
20     +           }
21     +           else {
22     +                   $page.=$text;
23     +           }
24     +   }, "tagname, text");
25     +   $p->handler(end => sub {
26     +           my $tagname=shift;
27     +           my $text=shift;
28     +           if ($tagname =~ /^h(\d+)$/i) {
29     +                   $page.="</a>$text";
30                 }
31                 else {
32                         $page.=$text;