ppcrcd/trunk/doc/gendoc.pl
sparky
cvs at pld-linux.org
Fri Mar 24 14:04:25 CET 2006
Author: sparky
Date: Fri Mar 24 14:02:33 2006
New Revision: 7304
Modified:
ppcrcd/trunk/doc/gendoc.pl
Log:
- code to cleanup html iteration
Modified: ppcrcd/trunk/doc/gendoc.pl
==============================================================================
--- ppcrcd/trunk/doc/gendoc.pl (original)
+++ ppcrcd/trunk/doc/gendoc.pl Fri Mar 24 14:02:33 2006
@@ -123,6 +123,7 @@
}
my $content = adddoc(shift @ARGV);
+$content = cleanhtml($content);
print <<EOF;
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
@@ -144,9 +145,116 @@
</style>
</head>
<body>
+
$content
</body>
</html>
EOF
+sub paragraph($$);
+my $text_to_clean;
+sub cleanhtml {
+ $text_to_clean = "$_[0]</end>";
+ return paragraph("","end");
+}
+
+sub gettag() {
+ $text_to_clean =~ s/^\s*<(.*?)>//;
+ return $1;
+}
+sub getword() {
+ $text_to_clean =~ s/^\s*([^<\s]*)//;
+ return $1;
+}
+
+sub paragraph($$) {
+ my ($step, $end) = @_;
+ my $clean="";
+ my $line=$step;
+ while (length $text_to_clean) {
+ my $tag = gettag();
+ my $word ="";
+ if ( $tag ) {
+ ( my $line_nosp = $line ) =~ s/\s*//g;
+ if ( $tag eq "/$end" ) {
+ $clean .= $line."\n" if length $line_nosp;
+ return $clean;
+ }
+ if ( $tag eq "div" or $tag eq "p" ) {
+ $clean .= $line."\n" if length $line_nosp;
+ $line = $step;
+ $clean .= $step."<$tag>\n";
+ $clean .= paragraph($step."\t", $tag);
+ $clean .= $step."</$tag>\n";
+ next;
+ }
+ if ( $tag =~ /^[biu]$/ ) {
+ $word = "<$tag>" . getword();
+ $tag = "";
+ }
+ if ( $tag =~ /^\/[biu]$/ ) {
+ $word = "<$tag>";
+ $tag = "";
+ }
+ if ( $tag =~ /^h[1-6]$/ ) {
+ $clean .= $line."\n" if length $line_nosp;
+ $clean .= "\n" unless length $line;
+ $line = paragraph($step." ", $tag);
+ $line =~ s/^\s*//;
+ chomp $line;
+ $clean .= $step . "<$tag>" . $line . "</$tag>\n";
+ $line = $step;
+ next;
+ }
+ if ( $tag eq "pre" ) {
+ $text_to_clean =~ s#^(.*?)</pre>##s;
+ my $pre = $1;
+ if ( $pre =~ /\n/ ) { #multiline
+ $clean .= $line."\n" if length $line_nosp;
+ $clean .= $step . "<pre>\n";
+ $clean .= $pre . "\n";
+ $clean .= $step . "</pre>\n";
+ $line = $step;
+ next;
+ } else {
+ $clean .= $line."\n" if length $line_nosp;
+ $clean .= $step. "<pre>" . $pre . "</pre>\n";
+ $line = $step;
+ next;
+ }
+ }
+ if ( $tag =~ /^hr\s*\/$/ ) {
+ $clean .= $line . "\n" if length $line_nosp;
+ $line = $step;
+ $clean .= $step . "<hr />\n";
+ next;
+ }
+ if ( $tag =~ /^br\s*\/$/ ) {
+ $clean .= $line if length $line_nosp;
+ $clean .= "<br />\n";
+ $line = $step;
+ next;
+ }
+ if ( length $tag ) {
+ warn "Unknown tag: <$tag>\n";
+ $word = "<$tag>";
+ }
+ }
+ $word = getword() unless length $word;
+ last unless $word;
+ ( my $tmpline = $line ) =~ s/\t/ /g;
+ if ( length ($tmpline . " " . $word) >= 80 ) {
+ $clean .= $line . "\n";
+ $line = $step . $word;
+ } else {
+ $line .= " " . $word;
+ }
+ }
+ warn "should never reach this point";
+ if ( length $line ) {
+ $clean .= $line . "\n";
+ }
+ return $clean;
+}
+
# vim: ts=4:sw=4
More information about the pld-cvs-commit
mailing list