#!/usr/local/bin/perl #-*- perl -*- # # Copyright (C) 2001 Ken'ichi Fukamachi # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # # $FML: html2sgml.pl,v 1.2 2001/05/01 13:45:53 fukachan Exp $ # use strict; use Carp; use vars qw($TR); use FileHandle; my $para = ''; my $hr = 0; my $tr = 0; my $listitem = 0; for my $file (@ARGV) { my $rh; my $tmpf = "/tmp/html2sgml.$$"; my $wh = new FileHandle "> $tmpf"; convert($file, $rh, $wh); $wh->close; my $rh = new FileHandle $tmpf; fix_output($rh); unlink $tmpf; } exit 0; sub convert { my ($file, $rh, $wh) = @_; my $fh = new FileHandle $file; while (<$fh>) { #

if (m@

@i) { print $wh "\n"; $para = 1; next; } if (/^\s*$/ && $para) { print $wh "\t" if $para eq 'tab'; print $wh "\n\n"; $para = 0; } # HR if (m@


@i) { print $wh "\n" if $hr; s@
@@gi; $hr = 1; } # A s@@\n\n@gi; # PRE s@
@@gi;
	s@
@@gi; # UL s@@@gi; if (m@
  • @i) { print $wh "\t" if $para eq 'tab' && $listitem; print $wh "\t\n\n" if $listitem; s@
  • @\n\t\n\t@gi; $para = "tab"; $listitem = 1; } if (m@@) { print $wh "\t" if $para eq 'tab' && $listitem;; print $wh "\t\n\n" if $listitem; $listitem = 0; } # BR s@
    @@gi; s@
    @@gi; s@@@gi; s@@@gi; s@@@gi; s@@@gi; s@@@gi; s@@@gi; # TABLE s@@\n \n@gi; s@
    @\n \n@gi; if (m@@) { $TR = $TR ? 'tbody' : 'thead'; $tr++; s@@<$TR>\n\t@gi; } if (m@@) { s@@@; s@$@\n\t@; } if ($tr && /^\s*$/) { print $wh "\t\n"; print $wh " \n"; $tr = 0; } print $wh $_; } } sub fix_output { my ($rh) = @_; my $buf; while (<$rh>) { $buf .= $_; } $buf =~ s@[\s\n]*@\n@g; print $buf; }