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;
}
} # }}}
-sub format (@) { #{{{
+sub sanitize (@) { #{{{
my %params=@_;
my $content=$params{content};
}
$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;