chiark
/
gitweb
/
~ianmdlvl
/
nailing-cargo.git
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
d5d5852a878268b4eb1ecd5c1f2136874e33b563
[nailing-cargo.git]
/
update-readme-toc
1
#!/usr/bin/perl -wni~
2
3
use strict;
4
use autodie;
5
6
our (@doc, @toc);
7
our $last;
8
9
if (1..m/^Table of Contents/) {
10
# before TOC
11
print;
12
} elsif (m/^\w/..0) {
13
push @doc, $_;
14
# after TOC
15
if (m/^-+$/ || m/^=+$/) {
16
my $lev = $& =~ m/^-/ ? ' ' : ' ';
17
my $href = $last;
18
$href =~ y/ A-Z-/-a-z/d;
19
push @toc, "${lev}* [$last](#$href)\n";
20
}
21
$last = $_;
22
chomp $last;
23
} else {
24
# in TOC
25
print if m/^===/;
26
}
27
28
END {
29
print @toc;
30
print @doc;
31
}