Import Debian changes 4.92-8+deb10u3
[hcoop/debian/exim4.git] / debian / lynx-dump-postprocess
1 #!/usr/bin/perl
2
3 open IN, '<&STDIN';
4 #open IN, 'dump';
5 {
6 local $/;
7 $content=<IN>;
8 }
9 close IN;
10
11 ($title,$body,$links) =
12 ($content =~
13 /^(.*)\n\s+_+\n\n
14 (\s+Table\ of\ Contents.*)
15 (References\n\n\s+1\..*)/sx);
16
17 die unless ($title);
18
19 print "$title\n".'-' x length($title)."\n\n";
20
21 # Sort out local links.
22 # The regex might not be entirely accurate.
23 foreach (split /\n/, $links) {
24 ($index, $url) = /^\s*(\d+)\. (.+)$/;
25 if ($url !~ /file:\/\/.*#.*$/) {
26 $links[$index] = $url;
27 }
28 }
29
30 $linkno=0;
31 # Split paragraphs
32 foreach (split /\n(?:\s+_+\n)?\n/, $body) {
33 my $footnote = '';
34 my $rest = $_;
35 while ( $rest =~ /^(.*?)\[(\d+)\](.*)$/s ) {
36 print $1;
37 if (defined $links[$2]) {
38 $linkno++;
39 print "[$linkno]";
40 $footnote.=" $linkno. $links[$2]\n";
41 }
42 $rest = $3;
43 }
44 print $rest;
45 print "\n\n";
46 if ($footnote ne '') {
47 print "$footnote\n";
48 }
49 }