X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/dc89360f03796465df96093b5a18a4abd661b4a3..98095ccac43b4b82d95bd8fd0ce3c8c16a325b22:/IkiWiki/Plugin/toc.pm diff --git a/IkiWiki/Plugin/toc.pm b/IkiWiki/Plugin/toc.pm index 070c07b0e..5380dd965 100644 --- a/IkiWiki/Plugin/toc.pm +++ b/IkiWiki/Plugin/toc.pm @@ -9,7 +9,7 @@ use HTML::Parser; sub import { #{{{ hook(type => "preprocess", id => "toc", call => \&preprocess); - hook(type => "format", id => "toc", call => \&format); + hook(type => "sanitize", id => "toc", call => \&sanitize); } # }}} my %tocpages; @@ -33,7 +33,7 @@ sub preprocess (@) { #{{{ } } # }}} -sub format (@) { #{{{ +sub sanitize (@) { #{{{ my %params=@_; my $content=$params{content}; @@ -86,17 +86,25 @@ sub format (@) { #{{{ } $liststarted=0; } + + $index.=&$indent."\n" unless $liststarted; + $liststarted=0; + $index.=&$indent."
  • ". + ""; $p->handler(text => sub { $page.=join("", @_); - $index.=&$indent."
  • \n" unless $liststarted; - $liststarted=0; - $index.=&$indent."
  • ". - "". - join("", @_). - "\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.="\n"; + } + $page.=join("", @_); + }, "tagname, text"); } else { $page.=$text;