#!/usr/bin/perl -w # Noweb filter to insert a HTML ToC after the 1st doc chunk, based in # tags. Takes no argument. # Copyright (c) 2003 by Yann Dirson # Distribute under the terms of the GNU General Public Licence, # version 2. # FIXME: # - does not handle multi-line headers # - some problems with holes in the hierarchy, including no top

# - style the ToC ! # - bad interaction with noidx, reported to Norman use strict; my @toc; my @data = ; # output 1st doc chunk, reserving @end marker until ($data[0] =~ m/^\@end docs 0/) { print $data[0]; shift @data; } my $indocchunk = 0; for (my $index = 0; $index <= $#data; $index++) { if ($data[$index] =~ m/^\@end docs/) { # this one first to limit to code chunks $indocchunk = 0; } elsif ($data[$index] =~ m/^\@begin docs/) { $indocchunk = 1; } elsif ($indocchunk and $data[$index] =~ m!^(.*<[hH]([1-6])(?:|\s[^>]*)>)(.*)(.*)$!) { $data[$index] = "$1$3$4\n"; push @toc, [ $2, $3, "htmlheader-$index" ]; } } # output ToC my $curlevel = 0; foreach my $entry (@toc) { # deal with nested itemized list while ($entry->[0] > $curlevel) { print "\@text
    \n\@nl\n"; $curlevel++; } while ($entry->[0] < $curlevel) { print "\@text
\n\@nl\n"; $curlevel--; } # the toc entry itself print "\@text
  • [2]\">$entry->[1]\n\@nl\n"; $curlevel = $entry->[0]; } # close nested itemized lists while (0 < $curlevel) { print "\@text \n\@nl\n"; $curlevel--; } # output everything else for (my $index = 0; $index <= $#data; $index++) { print $data[$index]; }