# tag can be placed on a line of its own without causing extra # vertical space as part of the preformatted text. $_[0] =~ s/\n$//; $_[0] =~ s/^\n//; $self->pre_out( $_[0] ); } elsif ( $self->{blockquote} ) { $_[0] =~ s/\A\s//; $self->blockquote_out( $_[0] ); } else { for ( split( /(\s+)/, $_[0] ) ) { next unless length $_; $self->out($_); } } } # ------------------------------------------------------------------------ sub vspace { my ( $self, $min, $add ) = @_; # This method sets the vspace attribute. When vspace is # defined, then a new line should be started. If vspace # is a nonzero value, then that should be taken as the # number of lines to be skipped before following text # is written out. # # You may think it odd to conflate the two concepts of # ending this paragraph, and asserting how much space should # follow; but it happens to work out pretty well. my $old = $self->{vspace}; if ( defined $old ) { my $new = $old; $new += $add || 0; $new = $min if $new < $min; $self->{vspace} = $new; } else { $self->{vspace} = $min; } ### vspace: $self->{vspace} $old; } # ------------------------------------------------------------------------ sub collect { push( @{ shift->{output} }, @_ ); } # ------------------------------------------------------------------------ sub out { confess "Must be overridden by subclass"; } # Output a word sub pre_out { confess "Must be overridden by subclass"; } sub adjust_lm { confess "Must be overridden by subclass"; } sub adjust_rm { confess "Must be overridden by subclass"; } # ------------------------------------------------------------------------ 1; __END__ =pod =for test_synopsis 1; __END__ =for stopwords formatters CPAN homepage =head1 NAME HTML::Formatter - Base class for HTML formatters =head1 VERSION version 2.12 =head1 SYNOPSIS use HTML::FormatSomething; my $infile = "whatever.html"; my $outfile = "whatever.file"; open OUT, ">$outfile" or die "Can't write-open $outfile: $!\n"; print OUT HTML::FormatSomething->format_file( $infile, 'option1' => 'value1', 'option2' => 'value2', ... ); close(OUT); =head1 DESCRIPTION HTML::Formatter is a base class for classes that take HTML and format it to some output format. When you take an object of such a base class and call C<$formatter->format( $tree )> with an L (or L) object, they return the appropriately formatted string for the input HTML. HTML formatters are able to format a HTML syntax tree into various printable formats. Different formatters produce output for different output media. Common for all formatters are that they will return the formatted output when the format() method is called. The format() method takes a HTML::Element object (usually the HTML::TreeBuilder root object) as parameter. =head1 METHODS =head2 new my $formatter = FormatterClass->new( option1 => value1, option2 => value2, ... ); This creates a new formatter object with the given options. =head2 format_file =head2 format_from_file $string = FormatterClass->format_file( $html_source, option1 => value1, option2 => value2, ... ); Return a string consisting of the result of using the given class to format the given HTML file according to the given (optional) options. Internally it calls C<< SomeClass->new( ... )->format( ... ) >> on a new HTML::TreeBuilder object based on the given HTML file. =head2 format_string =head2 format_from_string $string = FormatterClass->format_string( $html_source, option1 => value1, option2 => value2, ... ); Return a string consisting of the result of using the given class to format the given HTML source according to the given (optional) options. Internally it calls C<< SomeClass->new( ... )->format( ... ) >> on a new HTML::TreeBuilder object based on the given source. =head2 format my $render_string = $formatter->format( $html_tree_object ); This renders the given HTML object according to the options set for $formatter. After you've used a particular formatter object to format a particular HTML tree object, you probably should not use either again. =head1 SEE ALSO The three specific formatters:- =over =item L Format HTML into plain text =item L Format HTML into postscript =item L Format HTML into Rich Text Format =back Also the HTML manipulation libraries used - L, L and L =head1 INSTALLATION See perlmodinstall for information and options on installing Perl modules. =head1 BUGS AND LIMITATIONS You can make new bug reports, and view existing ones, through the web interface at L. =head1 AVAILABILITY The project homepage is L. The latest version of this module is available from the Comprehensive Perl Archive Network (CPAN). Visit L to find a CPAN site near you, or see L. =head1 AUTHORS =over 4 =item * Nigel Metheringham =item * Sean M Burke =item * Gisle Aas =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2015 by Nigel Metheringham, 2002-2005 Sean M Burke, 1999-2002 Gisle Aas. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut