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 text
  • HTML::FormatPS β€” Format HTML into postscript
  • HTML::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 πŸ‘‘πŸ‘‘πŸ‘‘


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