HTML::FormatText(3)
π HTML::FormatText β bestie's guide to turning HTML into plain text β¨
Okay so picture this: you've got a whole HTML tree and you just want the words, right? No bold, no italic, no underline, just the vibes in plaintext. That's exactly what HTML::FormatText does. It's a formatter that outputs plain text, and it is literally the main character of this page. π
One thing to know up front: all character attributes (bold/italic/underline) are ignored β it does not care about your drama. And formatting of HTML tables and forms is not implemented, so don't come for it about that. π
HTML::FormatText is built on HTML::Formatter, and the documentation for that module applies to this one too β especially "new" in HTML::Formatter, "format_file" in HTML::Formatter, and "format_string" in HTML::Formatter. Go read those if you want the full lore. iykyk. π
π VERSION π
version 2.16 β yes she's got a version number and yes it's iconic.
β¨ SYNOPSIS β¨
So the classic way, with a tree and everything:
use HTML::TreeBuilder;
$tree = HTML::TreeBuilder->new->parse_file("test.html");
use HTML::FormatText;
$formatter = HTML::FormatText->new(leftmargin => 0, rightmargin => 50);
print $formatter->format($tree);
Or, more simply β and honestly this is the lowkey slay way:
use HTML::FormatText;
my $string = HTML::FormatText->format_file(
'test.html',
leftmargin => 0, rightmargin => 50
);
π DESCRIPTION π
HTML::FormatText is a formatter that outputs plain text. All character attributes (bold/italic/underline) are ignored. Formatting of HTML tables and forms is not implemented. Periodt. π
It's built on HTML::Formatter, and the docs for that module apply here too β especially "new" in HTML::Formatter, "format_file" in HTML::Formatter, and "format_string" in HTML::Formatter. Highly recommend a read, fr fr. π«Ά
When you construct the formatter, you might specify these parameters:
leftmargin(aliaslm) β the column of the left margin. The default is3. So she starts a lil bit in from the edge, cute. πΈrightmargin(aliasrm) β the column of the right margin. The default is72. That's where the text wraps, so keep it in mind. π
Pro tip from me to you: these are the only two params listed here, so don't go inventing extra ones and then acting surprised, bestie. π
π₯ SEE ALSO π₯
HTML::Formatter β the parent module, the blueprint, the origin story. Go show it some love. π
π¦ AUTHORS π¦
These absolute legends made this happen:
- Nigel Metheringham
<nigelm@cpan.org>π - Sean M Burke
<sburke@cpan.org>β - Gisle Aas
<gisle@ActiveState.com>π
π 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. So yes, it's free, it's open, it's giving generous. π
π And that's the whole page, bestie.HTML::FormatTextversion2.16, brought to you with love on2023-07-03β go forth and format some plaintext, you've got this. Slay. π β¨
π¦ 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