Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Simplify tocgen.

Now that the headers are all sane, there is no noeed for so much jiggery pokery.
  • Loading branch information...
commit f6aafa5aa7f7946952fbac471859f6eee1679d71 1 parent 39d1878
@theory authored
Showing with 17 additions and 31 deletions.
  1. +17 −31 tocgen
View
48 tocgen
@@ -1,53 +1,39 @@
#!/usr/bin/env perl -n -pi
our $prevn;
-our $previd;
-our %seen;
BEGIN {
$prevn = 0;
- $previd = '';
print STDERR "<h1>Contents</h1>\n<ul>\n";
}
if (m{
- <h([123])\s+id=" # 1. hn
- (?:
- L[.]code[.+]([^.]+)(?:[^"]+) # 2. funcname
- | ([^"]+) # 3. id
- )
+ <h([123])\s+id=" # 1. hn
+ ([^"]+) # 3. id
">
- ( # 4. header
- (<code>[^(]+)?.+? # 5. label
+ ( # 4. header
+ (<code>[^(]+)?.+? # 5. label
)
</h\1>
}x) {
- # Clean up the ID a bit.
- my ($hn, $func, $id, $val, $label) = ($1, $2, $3, $4, $5);
- $id = $func || $id;
- $id =~ s{L?[.]code[.]}{}g;
- $id =~ s{[.]{2,}}{.}g;
- my $num = $seen{$id}++ || '';
+ my ($hn, $id, $val, $label) = ($1, $2, $3, $4);
- if ($previd ne $id) {
- $previd = $id;
- 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 {
+ 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"
}
- print STDERR qq{<li><a href="#$id$num">} . ($5 ? "$5()</code>" : $val) . "</a>";
+ } else {
+ $prevn = $hn;
}
+ print STDERR qq{<li><a href="#$id">$val</a>};
- $_ = qq{<h$hn id="$id$num">$val</h$hn>\n};
+ $_ = qq{<h$hn id="$id">$val</h$hn>\n};
}
END { print STDERR "</li>\n</ul>\n" }
Please sign in to comment.
Something went wrong with that request. Please try again.