diff options
author | Joey Hess <joey@gnu.kitenet.net> | 2009-12-25 15:28:18 -0500 |
---|---|---|
committer | Joey Hess <joey@gnu.kitenet.net> | 2009-12-25 15:28:18 -0500 |
commit | ffc9f25e734a8ca5397f2dfd09c1e31725624ee0 (patch) | |
tree | 08ecd456412bc99955466b007b9aee4c794fed0a /IkiWiki | |
parent | 7cf435b678e99ca9956de5d0454371b30c610b66 (diff) | |
download | ikiwiki-ffc9f25e734a8ca5397f2dfd09c1e31725624ee0.tar ikiwiki-ffc9f25e734a8ca5397f2dfd09c1e31725624ee0.tar.gz |
toc: Add startlevel parameter. (kerravonsen)
Diffstat (limited to 'IkiWiki')
-rw-r--r-- | IkiWiki/Plugin/toc.pm | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/IkiWiki/Plugin/toc.pm b/IkiWiki/Plugin/toc.pm index a585564e7..b8537d3eb 100644 --- a/IkiWiki/Plugin/toc.pm +++ b/IkiWiki/Plugin/toc.pm @@ -53,8 +53,8 @@ sub format (@) { my $page=""; my $index=""; my %anchors; - my $curlevel; - my $startlevel=0; + my $startlevel=($params{startlevel} ? $params{startlevel} : 0); + my $curlevel=$startlevel-1; my $liststarted=0; my $indent=sub { "\t" x $curlevel }; $p->handler(start => sub { @@ -65,12 +65,17 @@ sub format (@) { my $anchor="index".++$anchors{$level}."h$level"; $page.="$text<a name=\"$anchor\"></a>"; - # Take the first header level seen as the topmost level, + # 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. if (! $startlevel) { $startlevel=$level; $curlevel=$startlevel-1; } + elsif (defined $params{startlevel} && + $level < $params{startlevel}) { + return; + } elsif ($level < $startlevel) { $level=$startlevel; } |