forked from theory/pgtap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtocgen
More file actions
executable file
·39 lines (33 loc) · 885 Bytes
/
tocgen
File metadata and controls
executable file
·39 lines (33 loc) · 885 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/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" }