HTML::Formatter(3)
π HTML::Formatter π
okay bestie, welcome to the HTML::Formatter manual page β yes, that's the manual name, and this is a User Contributed Perl Documentation moment. Buckle up, we're getting into base-class territory π
πΈ NAME πΈ
HTML::Formatter β Base class for HTML formatters. It's the parent friend of the formatter classes, the main character that lets the other classes do their little formatting thing β¨
π VERSION π
version 2.16 β that's the version, bestie. Slay.
π¦ SYNOPSIS π¦
so here's the vibe of using it:
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);
β¨ DESCRIPTION β¨
Okay so 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 "$formatter-"format( $tree )> with an HTML::TreeBuilder (or HTML::Element) object, they return the appropriately formatted string for the input HTML. That's the whole lil' pipeline, and it's giving very demure, very mindful π§
HTML formatters are able to format an HTML syntax tree into various printable formats. Different formatters produce output for different output media. Common to all formatters is that they will return the formatted output when the format() method is called. And format() takes an HTML::Element object (usually the HTML::TreeBuilder root object) as its parameter. No cap, that's the contract π
The distribution name has been changed to HTML-Formatter as detailed in the DISTRIBUTION NAME section. Yes bestie, we'll get to that drama in a sec π
π§ METHODS π§
π new π
my $formatter = FormatterClass->new(
option1 => value1, option2 => value2, ...
);
This creates a new formatter object with the given options. Fresh object, fresh vibes, constructor core β¨
π¦ format_file / 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 "SomeClass->new( ... )->format( ... )" on a new HTML::TreeBuilder object based on the given HTML file. It's lowkey just file in, formatted string out, iykyk π
π format_string / 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 "SomeClass->new( ... )->format( ... )" on a new HTML::TreeBuilder object based on the given source. Same energy as format_file, but the source is already a string, bestie π
π format π
my $render_string = $formatter->format( $html_tree_object );
This renders the given HTML object according to the options set for $formatter. It's the main character method, periodt.
β οΈ after you've used a particular formatter object to format a particular HTML tree object, you probably should not use either again. That's the warning, bestie β don't reuse them, okay? π
π DISTRIBUTION NAME π
This module was originally named HTML-Format despite not containing a HTML::Format module within it. As rules on naming have been taken more seriously, and the PAUSE https://pause.perl.org/ toolchain adapted so that getting the distribution indexed was more difficult, it became obvious that the author should rename the distribution to HTML-Formatter matching the base HTML::Formatter module. Naming drama, but make it CPAN π¦
As of release 2.13 this is released as the HTML-Formatter distribution with corresponding changes to the git repository name and associated items. Glow-up complete β¨
Due to the way that the module is put together this should have no effect on code using the module. The only issues will be where the distribution name was used within dependancies. So yeah β no effect on your code, but maybe check your dependency strings, bestie π«Ά
π₯ SEE ALSO π₯
The three specific formatters, periodt:
HTML::FormatTextβ Format HTML into plain textHTML::FormatPSβ Format HTML into postscriptHTML::FormatRTFβ Format HTML into Rich Text Format
Also the HTML manipulation libraries used β HTML::TreeBuilder, HTML::Element and HTML::Tree. The whole tree-adjacent friend group π³π
π SUPPORT π
π Bugs / Feature Requests π
Please report any bugs or feature requests through the issue tracker at http://rt.cpan.org/Public/Dist/Display.html?Name=HTML-Formatter. You will be notified automatically of any progress on your issue. Bug reports get updates, bestie β that's the deal πβ¨
π» Source Code π»
This is open source software. The code repository is available for public review and contribution under the terms of the license.
https://github.com/nigelm/html-formatter
git clone https://github.com/nigelm/html-formatter.git
Go forth and contribute, open-source icon π
π AUTHORS π
- Nigel Metheringham β
nigelm@cpan.org - Sean M Burke β
sburke@cpan.org - Gisle Aas β
gisle@ActiveState.com
Author lineup ate, no cap πππ
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2016 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.
okay that's the whole page β footer check, bestie: source/version is perl v5.40.2, date is 2023-07-03, and this manual is HTML::Formatter(3). mwah π
π¦ where this page comes from
- alpine 3.22: perl-html-formatter-doc 2.16-r3 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms