#!/usr/bin/perl # normalize HTML # # TODO: strip comments use Getopt::Long; use File::Slurp; use strict; use warnings; my $force; GetOptions ("force|f"); my $stem = shift; my $_ = read_file( $stem . '.htm' ); # whitespace s/ / /mg; # page header s{]*;top:6[23]px;[^>]*>[^<]*

\s*}{}mg; # footnote foreach my $class ( map /(?<=\.)(ft\d+)(?={font-size:7px;)/mg, $_ ) { s{\(

\s*]*\sclass="$class">\d+

\s*]*>\)}{}mg; }; foreach my $class ( map /(?<=\.)(ft\d+)(?={font-size:6px;)/mg, $_ ) { s{]*>\(

\s*]*\sclass="$class">\d+

\s*]*>\) [^<]*

\s*}{}mg; }; # drop document headers s{.*?\s*}{}msg; s{\n\n.*?]*>\s*}{}msg; # unwrap similarly styled bolded paragraphs s{]*class="([^"]+)"[^>]*>[^<]+\K

\s*]*class="\1"[^>]*>}{ }mg; # headline s{]*>(TITLE \S+)

\s*]*>((?:(?!

}{

$1

\n

$2

}mg; s{]*>(SECTION \S+)

\s*]*>((?:(?!

}{

$1

\n

$2

}mg; s{]*>((?:Article|ANNEX) \S+)

\s*]*>(?:)?((?:(?!(?:)?

}{

$1

\n

$2

}mg; s{(]*>)(\d+)\. }{

$2

\n$1}mg; s{]*>\(([a-z])\)

}{

$1

}mg; s{(]*>)\(([ivx]+)\) }{
$2
\n$1}mg; s{]*>\(([ivx]+)\)

}{
$1
}mg; # unwrap s{(?<=\S)-(
|

\s*]*>)(?=[[:lower:]])}{}mg; s{\s*
\s*}{ }mg; # drop styling s{]*>}{

}mg; write_file( $stem . '.html', $_ ); print "DONE: $0 stem $stem\n";