package HTML::PrettyPrinter;
=head1 NAME
HTML::PrettyPrinter - generate nice HTML files from HTML syntax trees
=head1 SYNOPSIS
use HTML::TreeBuilder;
# generate a HTML syntax tree
my $tree = new HTML::TreeBuilder;
$tree->parse_file($file_name);
# modify the tree if you want
use HTML::PrettyPrinter;
my $hpp = new HTML::PrettyPrinter ('linelength' => 130,
'quote_attr' => 1);
# configure
$tree->address("0.1.0")->attr(_hpp_indent,0); # for an individual element
$hpp->set_force_nl(1,qw(body head)); # for tags
$hpp->set_force_nl(1,qw(@SECTIONS)); # as above
$hpp->set_nl_inside(0,'default!'); # for all tags
# format the source
my $linearray_ref = $hpp->format($tree);
print @$linearray_ref;
# alternative: print directly to filehandle
use FileHandle;
my $fh = new FileHandel ">$filenaem2";
if (defined $fh) {
$hpp->select($fh);
$hpp->format();
undef $fh;
$hpp->select(undef),
}
=head1 DESCRIPTION
HTML::PrettyPrinter produces nicely formatted HTML code from
a HTML syntax tree. It is especially usefull if the produced HTML file
shall be read or edited manually afterwards. Various parameters let you
adapt the output to different styles and requirements.
If you don't care how the HTML source looks like as long as it is valid
and readable by browsers, you should use the F method of
HTML::Element instead of the pretty printer. It is about five times faster.
The pretty printer will handle line wrapping, indention and structuring
by the way the whitespace in the tree is represented in the output.
Furthermore upper/lowercase markup and markup minimization, quoting of
attribute values, the encoding of entities and the presence of optional
end tags are configurable.
There are two types of parameters to influence the output, individual
parameters that are set on a per element and per tag basis and common
parameters that are set only once for each instance of a pretty printer.
In order to faciliate the configuration a mechanism to handle tag groups
is provided. Thus, it is possible to modify a parameter for a group of tags
(e.g. all known block elements) without writing each tag name explicitly.
Perhaps the code for tag groups will move to an other Perl module in the
future.
For HTML::Elements that require a special treatment like
, ,