]> sipb.mit.edu Git - ikiwiki.git/blob - doc/todo/toc_plugin:_set_a_header_ceiling___40__opposite_of_levels__61____41__.mdwn
(no commit message)
[ikiwiki.git] / doc / todo / toc_plugin:_set_a_header_ceiling___40__opposite_of_levels__61____41__.mdwn
1 It would be nice if the [[plugins/toc]] plugin let you specify a header level "ceiling" above which (or above and including which) the headers would not be incorporated into the toc.
2
3 Currently, the levels=X parameter lets you tweak how deep it will go for small headers, but I'd like to chop off the h1's (as I use them for my page title) -- [[Jon]]
4
5 > This change to toc.pm should do it. --[[KathrynAndersen]]
6
7 > > The patch looks vaguely OK to me but it's hard to tell without
8 > > context. It'd be much easier to review if you used unified diff
9 > > (`diff -u`), which is what `git diff` defaults to - almost all
10 > > projects prefer to receive changes as unified diffs (or as
11 > > branches in their chosen VCS, which is [[git]] here). --[[smcv]]
12
13 > > > Done. -- [[KathrynAndersen]]
14
15 > > > > Looks like Joey has now [[merged|done]] this. Thanks! --[[smcv]]
16
17         --- /files/git/other/ikiwiki/IkiWiki/Plugin/toc.pm      2009-11-16 12:44:00.352050178 +1100
18         +++ toc.pm      2009-12-26 06:36:06.686512552 +1100
19         @@ -53,8 +53,8 @@
20                 my $page="";
21                 my $index="";
22                 my %anchors;
23         -       my $curlevel;
24         -       my $startlevel=0;
25         +       my $startlevel=($params{startlevel} ? $params{startlevel} : 0);
26         +       my $curlevel=$startlevel-1;
27                 my $liststarted=0;
28                 my $indent=sub { "\t" x $curlevel };
29                 $p->handler(start => sub {
30         @@ -67,10 +67,16 @@
31                 
32                                 # Take the first header level seen as the topmost level,
33                                 # even if there are higher levels seen later on.
34         +                       # unless we're given startlevel as a parameter
35                                 if (! $startlevel) {
36                                         $startlevel=$level;
37                                         $curlevel=$startlevel-1;
38                                 }
39         +                       elsif (defined $params{startlevel}
40         +                              and $level < $params{startlevel})
41         +                       {
42         +                           return;
43         +                       }
44                                 elsif ($level < $startlevel) {
45                                         $level=$startlevel;
46                                 }
47
48 [[!tag patch]]