#!/usr/bin/perl use strict; use warnings; use utf8; my $filename = shift; my $html = shift; my $file; { local $/; undef $/; open G, "<:utf8", $filename or die "Can't open [$filename: $!]"; $file = ; close G; } my %notes; for ($file) { s/.*\*\*\*\s*START OF[^\*]+\*\*\*\n+//s; s/End of the Project Gutenberg EBook of.*$//sm; s{^.*?(\n\n\n\n\n)}{$1}sm; s{^\n+(([. \w]+)\n(\n([. \w]+)\n)*)\n\n\n}{

$1

}m; # s{\n([. [:upper:]]+)\n}{

$1

}g; s!_([^_]+)_!$1!g; s!\+([^+]+)\+!$1!g; s!\^([[:alpha:]]+)!$1!g; # s!\n\s+\[(\d+)\](.*?)(?=\n\S)!$notes{$1}=$2;""!ges; s!&!&!g; s!--!—!g; s{\n\n}{

\n\n

}g; } open H, ">:utf8", $html or die "Can't create [$filename: $!]"; select H; print header(); print $file; print footnotes(%notes); print footer(); close H; sub footnotes { my %notes = @_; if (%notes) { my $ret = "


\n"; for my $n (sort keys %notes) { $ret .= "
$n $notes{$n}"; } return $ret; } return ""; } sub header { return <<"EOH"; ... EOH } sub footer { return <<"EOH"; EOH }