Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 40 lines (33 sloc) 0.885 kB
#!/usr/bin/env perl -n -pi
our $prevn;
BEGIN {
$prevn = 0;
print STDERR "<h1>Contents</h1>\n<ul>\n";
}
if (m{
<h([123])\s+id=" # 1. hn
([^"]+) # 3. id
">
( # 4. header
(<code>[^(]+)?.+? # 5. label
)
</h\1>
}x) {
my ($hn, $id, $val, $label) = ($1, $2, $3, $4);
if ($prevn) {
if ($hn != $prevn) {
print STDERR $hn > $prevn
? $hn - $prevn > 1
? "<ul><li><ul>" : "<ul>\n" : $prevn - $hn > 1
? "</li></ul></li></ul></li>\n" : "</li></ul></li>\n";
$prevn = $hn;
} else {
print STDERR "</li>\n"
}
} else {
$prevn = $hn;
}
print STDERR qq{<li><a href="#$id">$val</a>};
$_ = qq{<h$hn id="$id">$val</h$hn>\n};
}
END { print STDERR "</li>\n</ul>\n" }
Jump to Line
Something went wrong with that request. Please try again.