HTML::Clean(3pm)

πŸ“¦
version 1.4 Β· 3 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– HTML::Clean β€” User Contributed Perl Documentation πŸ’–

okay bestie, welcome to HTML::Clean(3pm), the little Perl module that cleans up HTML code for web browsers, not humans. yes. it is literally built to make your markup look cursed so the browser eats it faster. we love a humble icon. πŸŽ€


✨ NAME ✨

HTML::Clean β€” Cleans up HTML code for web browsers, not humans

fr fr, the humans get the pretty version, the browser gets the skinny version. that's the whole vibe.

🌸 SYNOPSIS 🌸

use HTML::Clean;
$h = HTML::Clean->new($filename); # or..
$h = HTML::Clean->new($htmlcode);

$h->compat();
$h->strip();
$data = $h->data();
print $$data;

look at that. five lines. no cap, that's the entire starter pack. 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so HTML::Clean wraps up a whole bunch of the classic tricks for shrinking your HTML files down to size. and the numbers?? typically you can save between 10% and 50% of the size of an HTML file using these methods. that's not a drill. πŸ’…

it provides the following features, and yes this is the list, we're not skipping anything:

  • Remove unneeded whitespace (beginning of line, etc)
  • Remove unneeded META elements.
  • Remove HTML comments (except for styles, javascript and SSI)
  • Replace tags with equivalent shorter tags (<strong> --> <b>)
  • etc.

the entire process is configurable, so you can pick and choose what you want to clean. main character energy: you decide. ✨


πŸ‘‘ THE HTML::Clean CLASS πŸ‘‘

πŸ’œ $h = HTML::Clean->new($dataorfile, [$level]);

this creates a new HTML::Clean object. it's a prerequisite for all other functions in this module β€” like, you literally cannot skip this step, bestie. πŸ™ˆ

the $dataorfile parameter supplies the input HTML. it's either a filename, or a reference to a scalar value holding the HTML. for example, both of these are valid and iconic:

$h = HTML::Clean->new("/htdocs/index.html");
$html = "<strong>Hello!</strong>";
$h = HTML::Clean->new(\$html);

an optional 'level' parameter controls the level of optimization performed. levels range from 1 to 9. Level 1 includes only simple fast optimizations. Level 9 includes all optimizations. slay. go big or stay at 1. πŸ”₯


🧚 $h->initialize($dataorfile)

this function allows you to reinitialize the HTML data used by the current object. super useful if you are processing many files β€” you don't have to throw away the whole object, just re-feed it. πŸ“

$dataorfile has the same usage as the new method. same rules, same formats, same energy.

Return 0 for an error, 1 for success. it's giving very pass/fail. πŸ’€


🌈 $h->level([$level])

get/set the optimization level. $level is a number from 1 to 9. that's it, that's the whole function. lowkey convenient. ⭐


✨ $myref = $h->data()

Returns the current HTML data as a scalar reference.

note the double dollar when you print it. $$data bestie, don't forget, or you'll be printing memory addresses and crying. 😭

πŸŽ€ strip(\%options);

Removes excess space from HTML. πŸ’…

you can control the optimizations used by specifying them in the %options hash reference.

the following options are recognized:

boolean values (0 or 1 values)

  • whitespace β€” Remove excess whitespace
  • shortertags β€” <strong> -> <b>, etc..
  • blink β€” No blink tags.
  • contenttype β€” Remove default contenttype.
  • comments β€” Remove excess comments.
  • entities β€” &quot; -> ", etc.
  • dequote β€” remove quotes from tag parameters where possible.
  • defcolor β€” recode colors in shorter form. (#ffffff -> white, etc.)
  • javascript β€” remove excess spaces and newlines in javascript code.
  • htmldefaults β€” remove default values for some html tags
  • lowercasetags β€” translate all HTML tags to lowercase

parameterized values

  • meta β€” Takes a space separated list of meta tags to remove, default "GENERATOR FORMATTER"
  • emptytags β€” Takes a space separated list of tags to remove when there is no content between the start and end tag, like this: <b></b>. The default is 'b i font center'

⚠️ GIRL PLEASE READ THIS ONE ⚠️ Please note that if your HTML includes preformatted regions (this means, if it includes <pre>...</pre>, we do not suggest removing whitespace, as it will alter the rendered defaults.

HTML::Clean will print out a warning if it finds a preformatted region and is requested to strip whitespace. and bestie, there IS a way to silence it β€” In order to prevent this, specify that you don't want to strip whitespace, i.e.

$h->strip( {whitespace => 0} );

boom. no warning, no rearranged <pre> blocks, no drama. 🫢


🌟 compat()

this function improves the cross-platform compatibility of your HTML. Currently checks for the following problems:

  • Insuring all IMG tags have ALT elements.
  • Use of Arial, Futura, or Verdana as a font face.
  • Positioning the <TITLE> tag immediately after the <head> tag.

three lil checks, all of them obsessed with making your page behave everywhere. ✨


πŸ’– defrontpage();

this function converts pages created with Microsoft Frontpage to something a Unix server will understand a bit better. Currently does the following:

  • Converts Frontpage 'hit counters' into a unix specific format.
  • Removes some frontpage specific html comments

de-Frontpaging a page is genuinely a public service. thank you for your work. πŸŽ€


πŸ‘€ SEE ALSO πŸ‘€

Modules

  • FrontPage::Web, FrontPage::File

Web Sites


🫢 AUTHORS and CO-AUTHORS 🫢

  • Paul Lindner for the International Telecommunication Union (ITU)
  • Pavel Kuptsov <admin@modernperl.ru>

The HTML::Strip module is Copyright (c) 1998,99 by the ITU, Geneva Switzerland. All rights reserved.

You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file.


and that's the whole page, bestie!! 🌈 this lovely lil doc shipped with perl v5.36.0 and is dated 2022-10-15 β€” go forth and shrink your markup, you absolute icon. πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from