aboutsummaryrefslogtreecommitdiff
path: root/doc/bugs/Problem_with_toc.pm_plug-in.mdwn
blob: a5fe6b923d9323a4d13de173e82490d9761451c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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).

Here is a patch for toc.pm for producing non-empty 'a' elements.

    --- IkiWiki/Plugin/toc.pm.orig	Thu Jun  7 11:53:53 2007
    +++ IkiWiki/Plugin/toc.pm	Thu Jun  7 13:00:00 2007
    @@ -47,7 +47,7 @@ sub format (@) { #{{{
     		if ($tagname =~ /^h(\d+)$/i) {
     			my $level=$1;
     			my $anchor="index".++$anchors{$level}."h$level";
    -			$page.="$text<a name=\"$anchor\" />";
    +			$page.="$text<a name=\"$anchor\">";
     	
     			# Take the first header level seen as the topmost level,
     			# even if there are higher levels seen later on.
    @@ -90,6 +90,16 @@ sub format (@) { #{{{
     					"</a>\n";
     				$p->handler(text => undef);
     			}, "dtext");
    +		}
    +		else {
    +			$page.=$text;
    +		}
    +	}, "tagname, text");
    +	$p->handler(end => sub {
    +		my $tagname=shift;
    +		my $text=shift;
    +		if ($tagname =~ /^h(\d+)$/i) {
    +			$page.="</a>$text";
     		}
     		else {
     			$page.=$text;