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 (alias lm) β€” the column of the left margin. The default is 3. So she starts a lil bit in from the edge, cute. 🌸
  • rightmargin (alias rm) β€” the column of the right margin. The default is 72. 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> 🌟

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::FormatText version 2.16, brought to you with love on 2023-07-03 β€” go forth and format some plaintext, you've got this. Slay. πŸ’…βœ¨
πŸ“¦ where this page comes from