#!/usr/bin/perl ########################################### # htmlstylize -- # Mike Schilli, 2002 (m@perlmeister.com) ########################################### use warnings; use strict; our $VERSION = "1.0"; our $CVSVERSION = '$Revision: 1.4 $'; use HTML::Parser 3.0; use File::Basename; use Pod::Usage; use Getopt::Long; GetOptions ("fontface=s" => \my $fontface, "bgcolor=s" => \my $bgcolor, "header=s" => \my $header, "footer=s" => \my $footer, "help" => \my $help, "version" => \my $version, ); pod2usage(-verbose => 2) if $help; die "v$VERSION\n" if $version; my $data = join '', <>; $bgcolor ||= "#ffdcba"; $fontface ||= "verdana"; my $title = 0; my $parser = HTML::Parser->new( start_h => [ sub { handle("start", @_); }, 'tagname,attrseq,attr' ], end_h => [ sub { handle("end", @_); }, 'tagname,attrseq,attr' ], text_h => [ sub { return unless $_[0] !~ /^\s+$/s; if($title) { print "$_[0]"; } else { print "$_[0]\n"; } }, 'text' ], default_h => [ sub { print @_ }, 'text' ], ); $parser->parse($data) || die $!; ########################################### sub handle { ########################################### my ($ctrl, $tagname, $attrseq, $attr) = @_; my $slash = ($ctrl eq "start" ? "" : "/"); if($tagname eq "title") { $title = 1 if $ctrl eq "start"; $title = 0 if $ctrl eq "end"; } if($tagname eq "body") { if(!exists $attr->{bgcolor}) { push @$attrseq, "bgcolor"; } $attr->{bgcolor} = $bgcolor; } print "<$slash" . uc($tagname) . " " . join(" ", map { uc($_) . '="' . $attr->{$_} . '"' } @$attrseq ) . ">"; } __END__ =head1 NAME htmlstylize - Stylize dull HTML output =head1 DOWNLOAD _SRC_HERE_ =head1 SYNOPSIS pod2html_stylize [--help] [--version] [--bgcolor bgcolor] [--fontface fontface] [file] ... Options: --help: Print the manual page --version: Print the current release version --bgcolor: Background color --fontface: Font face =head1 OPTIONS =over 8 =item B<--help> Prints this manual page in text format. =item B<--version> Print the current release version =item B<--bgcolor> Specify the desired background color of the page as either a text string (like "white" or "darkgreen") or as a hex number (like "#ffdcba"). =item B<--fontface> Specify the desired font face to be used in the HTML of the destination document ("verdana", "arial", etc.) =back =head1 DESCRIPTION C provides a poor man's interface to transform the dull output of C into HTML documents with customized font faces and background colors. Yes, I know, a cascading style sheet would be a better solution, but I'm operating ancient browsers :). C reads its input either from files specified on the command line or from STDIN. Output is written to STDOUT. =head1 EXAMPLES To use the default color and font face: htmlstylize manual.html >nicemanual.html Or to use customized values: htmlstylize --fontface arial \ --bgcolor darkgreen manual.html >nicemanual.html =head1 LEGALESE Copyright 2002 by Mike Schilli, all rights reserved. This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHOR 2002, Mike Schilli