1 [[!template id=plugin name=headinganchors author="[[PaulWise]]"]]
2 [[ikiwiki/directive/cosa]]
4 This is a simple plugin to add ids (which will serve as [[anchor]]s) to all headings, based on their text. It
5 works as a postprocessing filter, allowing it to work on mdwn, wiki, html,
6 rst and any other format that produces html. The code is available here:
9 # quick HTML heading id adder by Paul Wise
10 package IkiWiki::Plugin::headinganchors;
17 hook(type => "sanitize", id => "headinganchors", call => \&headinganchors);
25 $str =~ s/[&\?"\'\.,\(\)!]//mig;
26 $str =~ s/[^a-z]/_/mig;
30 sub headinganchors (@) {
32 my $content=$params{content};
33 $content=~s{<h([0-9])>([^>]*)</h([0-9])>}{'<h'.$1.' id="'.text_to_anchor($2).'">'.$2.'</h'.$3.'>'}gie;