blob: 97b2f5f14bb690028c48f9c01a7fa1a8371dc790 (
plain)
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/perl
while (<STDIN>) { $content.=$_ }
# open IN, 'dump'; while (<IN>) { $content.=$_ } close IN;
($title,$body,$links) =
($content =~ /(?:\n #\[1\].*)?\n(.*?)\n\s{5}_{65}\n\n(.*)\n\nReferences\n\n( 1. .*:.*)$/s);
print "$title\n".'-' x length($title)."\n\n";
# Sort out local links.
# The regex might not be entirely accurate.
foreach (split /\n/, $links) {
($index, $url) = /^\s*(\d+)\. (.+)$/;
if ($url !~ /file:\/\/.*#.*$/) {
$links[$index] = $url;
}
}
$linkno=0;
# Split paragraphs
foreach (split /\n(?: {5}_{65}\n)?\n/, $body) {
my $footnote = '';
my $rest = $_;
while ( $rest =~ /^(.*?)\[(\d+)\](.*)$/s ) {
print $1;
if (defined $links[$2]) {
$linkno++;
print "[$linkno]";
$footnote.=" $linkno. $links[$2]\n";
}
$rest = $3;
}
print $rest;
print "\n\n";
if ($footnote ne '') {
print "$footnote\n";
}
}
|