summaryrefslogtreecommitdiff
path: root/mkhtm2html-1
blob: ced72e75176ef864f5c80e86611372c2bed9b6a5 (plain)
  1. #!/usr/bin/perl
  2. # normalize HTML
  3. #
  4. # TODO: strip <!-- ... --> comments
  5. use Getopt::Long;
  6. use File::Slurp;
  7. use strict;
  8. use warnings;
  9. my $force;
  10. GetOptions ("force|f");
  11. my $stem = shift;
  12. my $_ = read_file( $stem . '.htm' );
  13. # whitespace
  14. s/&#160;/ /mg;
  15. # page header
  16. s{<P\b[^>]*;top:6[23]px;[^>]*>[^<]*</P>\s*}{}mg;
  17. # footnote
  18. foreach my $class ( map /(?<=\.)(ft\d+)(?={font-size:7px;)/mg, $_ ) {
  19. s{\(</P>\s*<P\b[^>]*\sclass="$class">\d+</P>\s*<P\b[^>]*>\)}{}mg;
  20. };
  21. foreach my $class ( map /(?<=\.)(ft\d+)(?={font-size:6px;)/mg, $_ ) {
  22. s{<P\b[^>]*>\(</P>\s*<P\b[^>]*\sclass="$class">\d+</P>\s*<P\b[^>]*>\) [^<]*</P>\s*}{}mg;
  23. };
  24. # drop document headers
  25. s{<HEAD>.*?</HEAD>\s*}{}msg;
  26. s{</DIV>\n</BODY>\n</HTML>.*?<DIV\b[^>]*>\s*}{}msg;
  27. # unwrap similarly styled bolded paragraphs
  28. s{<P\b[^>]*class="([^"]+)"[^>]*><b>[^<]+\K</b></P>\s*<P\b[^>]*class="\1"[^>]*><b>}{ }mg;
  29. # headline
  30. s{<P\b[^>]*>(TITLE \S+)</P>\s*<P\b[^>]*><b>((?:(?!</P\b).)+.)</b></P>}{<H1>$1</H1>\n<H2>$2</H2>}mg;
  31. s{<P\b[^>]*><i>(SECTION \S+)</i></P>\s*<P\b[^>]*><i><b>((?:(?!</P\b).)+.)</b></i></P>}{<H1>$1</H1>\n<H2>$2</H2>}mg;
  32. s{<P\b[^>]*><i>((?:Article|ANNEX) \S+)</i></P>\s*<P\b[^>]*>(?:<i>)?<b>((?:(?!</P\b).)+.)</b>(?:</i>)?</P>}{<H1>$1</H1>\n<H2>$2</H2>}mg;
  33. s{(<P\b[^>]*>)(\d+)\. }{<H3>$2</H3>\n$1}mg;
  34. s{<P\b[^>]*>\(([a-z])\)</P>}{<H4>$1</H4>}mg;
  35. s{(<P\b[^>]*>)\(([ivx]+)\) }{<H5>$2</H5>\n$1}mg;
  36. s{<P\b[^>]*>\(([ivx]+)\)</P>}{<H5>$1</H5>}mg;
  37. # unwrap
  38. s{(?<=\S)-(<br/>|</P>\s*<P\b[^>]*>)(?=[[:lower:]])}{}mg;
  39. s{\s*<br/>\s*}{ }mg;
  40. # drop styling
  41. s{<P\b[^>]*>}{<P>}mg;
  42. write_file( $stem . '.html', $_ );
  43. print "DONE: $0 stem $stem\n";