Verified Commit 27d5d9d1 authored by Antoine Beaupré's avatar Antoine Beaupré
Browse files

use heading identifiers in TOC links

reasoning: if headings have identifiers, they are probably more useful
anchors than the automatically generated anchors we build in the toc
plugin. this can happen if, for example, you use the `multimarkdown`
plugin, which inserts `id` tags for every header it encounters. this
also leverages the `headinganchors` plugin nicely.

keeps backwards-compatibility with old toc-generated #indexXhY
parent f65eae21
......@@ -59,13 +59,16 @@ sub format (@) {
my $liststarted=0;
my $indent=sub { "\t" x $curlevel };
$p->handler(start => sub {
my $tagname=shift;
my $text=shift;
my ($tagname, $text, $attr) = @_;
if ($tagname =~ /^h(\d+)$/i) {
my $level=$1;
my $anchor="index".++$anchors{$level}."h$level";
$page.="$text<a name=\"$anchor\"></a>";
# if the heading already has a unique ID, use that instead in TOC
if ($attr->{id}) {
$anchor = $attr->{id};
# Unless we're given startlevel as a parameter,
# take the first header level seen as the topmost level,
# even if there are higher levels seen later on.
......@@ -124,7 +127,7 @@ sub format (@) {
else {
}, "tagname, text");
}, "tagname, text, attr");
$p->handler(default => sub { $page.=join("", @_) }, "text");
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment