#! /usr/bin/perl -w
#
# htmltoc - a tool to make a table of contents from a particular html document.
#
# Copyright (C) 1999 Satoru Takabayashi
# All rights reserved.
# This is free software with ABSOLUTELY NO WARRANTY.
#
# You can redistribute it and/or modify it under the terms of
# the GNU General Public License version 2.
#
use NKF;
$_ = join '', <>;
$_ = nkf("-e", $_);
my $n = 0;
while (1) {
if (s/^\s*]*>([^<>]*)<\/a><\/h\1>//ism) {
$level = $1;
$anchor = $2;
$heading = $3;
} elsif (s/^\s*([^<>]*)<\/h\1>//ism) {
$level = $1;
$anchor = $2;
$heading = $3;
} else {
last;
};
if ($level > $n) {
print " " x ($level - 2);
print "\n";
} elsif ($level < $n) {
for ($i = $level; $i < $n; $i++) {
print " " x ($n - $i);
print "
\n";
}
}
$n = $level;
print " " x ($n - 2);
print "$heading\n";
}
for ($i = 1; $i < $n; $i++) {
print " " x ($n - $i -1);
print "\n";
}