1
0
Fork 0
virtualbox/debian/lynx-dump-postprocess
Daniel Baumann aef005766e
Adding debian version 7.0.20-dfsg-1.2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
2025-06-22 09:56:25 +02:00

51 lines
939 B
Perl
Executable file

#!/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";
}
}