summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfukachan <fukachan>2001-04-24 13:46:31 +0000
committerfukachan <fukachan>2001-04-24 13:46:31 +0000
commit3644b4a55999fe46d499e573c03e5724fdcb4db1 (patch)
treed9a8a59012a56ca021514a6f46a1ce125ccfc0c3
parent30965f900d2223d4a797a9b11b0fc1413683af67 (diff)
downloadfml8-3644b4a55999fe46d499e573c03e5724fdcb4db1.tar.gz
fml8-3644b4a55999fe46d499e573c03e5724fdcb4db1.tar.bz2
fml8-3644b4a55999fe46d499e573c03e5724fdcb4db1.zip
handle <tbody> more smartly
remove several tags for fashion
-rwxr-xr-xdoc/bin/html2sgml.pl167
1 files changed, 108 insertions, 59 deletions
diff --git a/doc/bin/html2sgml.pl b/doc/bin/html2sgml.pl
index c5e1c28d..aed33dbb 100755
--- a/doc/bin/html2sgml.pl
+++ b/doc/bin/html2sgml.pl
@@ -5,87 +5,136 @@
# 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.1 2001/04/23 14:37:42 fukachan Exp $
+# $FML: html2sgml.pl,v 1.2 2001/04/24 03:41:52 fukachan Exp $
#
use strict;
use Carp;
use vars qw($TR);
+use FileHandle;
my $para = '';
my $hr = 0;
my $tr = 0;
my $listitem = 0;
-while (<>) {
- # <P>
- if (m@<P>@i) {
- print "<para>\n";
- $para = 1;
- next;
- }
+for my $file (@ARGV) {
+ my $rh;
- if (/^\s*$/ && $para) {
- print "\t" if $para eq 'tab';
- print "</para>\n\n";
- $para = 0;
- }
+ my $tmpf = "/tmp/html2sgml.$$";
+ my $wh = new FileHandle "> $tmpf";
+ convert($file, $rh, $wh);
+ $wh->close;
- # HR
- if (m@<HR>@i) {
- print "</sect1>\n" if $hr;
- s@<HR>@<sect1>@gi;
- $hr = 1;
- }
+ my $rh = new FileHandle $tmpf;
+ fix_output($rh);
- # A
- s@<A\s*HREF=@<ulink url=@gi;
- s@</A>@</ulink>@gi;
+ unlink $tmpf;
+}
- # PRE
- s@<PRE>@<programlisting>@gi;
- s@</PRE>@</programlisting>@gi;
+exit 0;
- # UL
- s@<UL>@<itemizedlist>@gi;
- s@</UL>@</itemizedlist>@gi;
- if (m@<LI>@i) {
- print "\t" if $para eq 'tab' && $listitem;
- print "\t</listitem>\n\n" if $listitem;
- s@<LI>@<listitem>\n\t<para>\n\t@gi;
- $para = "tab";
- $listitem = 1;
- }
+sub convert
+{
+ my ($file, $rh, $wh) = @_;
- if (m@</itemizedlist>@) {
- print "\t" if $para eq 'tab' && $listitem;;
- print "\t</listitem>\n\n" if $listitem;
- $listitem = 0;
- }
+ my $fh = new FileHandle $file;
+ while (<$fh>) {
+ # <P>
+ if (m@<P>@i) {
+ print $wh "<para>\n";
+ $para = 1;
+ next;
+ }
- # BR
- s@<BR>@@gi;
+ if (/^\s*$/ && $para) {
+ print $wh "\t" if $para eq 'tab';
+ print $wh "</para>\n\n";
+ $para = 0;
+ }
- # TABLE
- s@<TABLE.*>@<table>@gi;
- if (m@<TR>@) {
- $TR = $TR ? 'tbody' : 'thead';
- $tr++;
- s@<TR>@<${TR}>\n\t<row>@gi;
- }
- if (m@<TD>@) {
- s@<TD>@<entry>@;
- s@$@</entry>@;
+ # HR
+ if (m@<HR>@i) {
+ print $wh "</sect1>\n" if $hr;
+ s@<HR>@<sect1>@gi;
+ $hr = 1;
+ }
+
+ # A
+ s@<A\s*HREF=@\n<ulink url=@gi;
+ s@</A>@\n</ulink>\n@gi;
+
+ # PRE
+ s@<PRE>@<programlisting>@gi;
+ s@</PRE>@</programlisting>@gi;
+
+ # UL
+ s@<UL>@<itemizedlist>@gi;
+ s@</UL>@</itemizedlist>@gi;
+
+ if (m@<LI>@i) {
+ print $wh "\t" if $para eq 'tab' && $listitem;
+ print $wh "\t</listitem>\n\n" if $listitem;
+ s@<LI>@<listitem>\n\t<para>\n\t@gi;
+ $para = "tab";
+ $listitem = 1;
+ }
+
+ if (m@</itemizedlist>@) {
+ print $wh "\t" if $para eq 'tab' && $listitem;;
+ print $wh "\t</listitem>\n\n" if $listitem;
+ $listitem = 0;
+ }
+
+
+ # BR
+ s@<HR>@@gi;
+ s@<BR>@@gi;
+ s@<EM>@@gi;
+ s@</EM>@@gi;
+ s@<B>@@gi;
+ s@</B>@@gi;
+ s@<I>@@gi;
+ s@</I>@@gi;
+
+
+ # TABLE
+ s@<TABLE.*>@<table>\n <tgroup cols=2>\n@gi;
+ s@</TABLE>@\n </tgroup>\n</table>@gi;
+ if (m@<TR>@) {
+ $TR = $TR ? 'tbody' : 'thead';
+ $tr++;
+ s@<TR>@<$TR>\n\t<row>@gi;
+ }
+
+ if (m@<TD>@) {
+ s@<TD>@<entry>@;
+ s@$@\n\t</entry>@;
+ }
+
+ if ($tr && /^\s*$/) {
+ print $wh "\t</row>\n";
+ print $wh " </${TR}>\n";
+ $tr = 0;
+ }
+
+ print $wh $_;
}
- if ($tr && /^\s*$/) {
- print "\t</row>\n";
- print " </${TR}>\n";
- $tr = 0;
+}
+
+
+sub fix_output
+{
+ my ($rh) = @_;
+ my $buf;
+
+ while (<$rh>) {
+ $buf .= $_;
}
- print;
-}
+ $buf =~ s@</tbody>[\s\n]*<tbody>@\n@g;
-exit 0;
+ print $buf;
+}