blob: 644e49c021ccc8d6c11e24c1e6607ef77d121cfd (
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
40
41
42
43
44
45
46
47
48
49
50
51
|
#!/usr/bin/perl
# taken from the exim4 package
open IN, '<&STDIN';
#open IN, 'dump';
{
local $/;
$content=<IN>;
}
close IN;
($title,$body,$links) =
($content =~
/^(.*)\n\s+_+\n\n
(\s+Table\ of\ Contents.*)
(References\n\n\s+1\..*)/sx);
die unless ($title);
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(?:\s+_+\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";
}
}
|