]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/toc.pm
the pre-receive wrapper needs to be suid after all
[ikiwiki.git] / IkiWiki / Plugin / toc.pm
index 070c07b0e96093b4c82c3bb9e6c8751dcb7ed414..dff9d9aa5356e5928de0a9ddd654217f2165af84 100644 (file)
@@ -8,10 +8,19 @@ use IkiWiki 2.00;
 use HTML::Parser;
 
 sub import { #{{{
+       hook(type => "getsetup", id => "toc", call => \&getsetup);
        hook(type => "preprocess", id => "toc", call => \&preprocess);
        hook(type => "format", id => "toc", call => \&format);
 } # }}}
 
+sub getsetup () { #{{{
+       return
+               plugin => {
+                       safe => 1,
+                       rebuild => undef,
+               },
+} #}}}
+
 my %tocpages;
 
 sub preprocess (@) { #{{{
@@ -86,17 +95,25 @@ sub format (@) { #{{{
                                }
                                $liststarted=0;
                        }
+                               
+                       $index.=&$indent."</li>\n" unless $liststarted;
+                       $liststarted=0;
+                       $index.=&$indent."<li class=\"L$curlevel\">".
+                               "<a href=\"#$anchor\">";
        
                        $p->handler(text => sub {
                                $page.=join("", @_);
-                               $index.=&$indent."</li>\n" unless $liststarted;
-                               $liststarted=0;
-                               $index.=&$indent."<li class=\"L$curlevel\">".
-                                       "<a href=\"#$anchor\">".
-                                       join("", @_).
-                                       "</a>\n";
-                               $p->handler(text => undef);
+                               $index.=join("", @_);
                        }, "dtext");
+                       $p->handler(end => sub {
+                               my $tagname=shift;
+                               if ($tagname =~ /^h(\d+)$/i) {
+                                       $p->handler(text => undef);
+                                       $p->handler(end => undef);
+                                       $index.="</a>\n";
+                               }
+                               $page.=join("", @_);
+                       }, "tagname, text");
                }
                else {
                        $page.=$text;