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