HTML::...malizer(3pm)
π HTML::WikiConverter::Normalizer π
okay bestie, gather round β this is the manual page for HTML::WikiConverter::Normalizer, which lives in the Perl docs as HTML::...malizer(3pm) (they truncated it, tragic, but we move). It's giving "convert CSS styles to (roughly) corresponding HTML" and honestly? iconic behaviour.
β¨ NAME β¨
HTML::WikiConverter::Normalizer β Convert CSS styles to (roughly) corresponding HTML
πΈ SYNOPSIS πΈ
use HTML::TreeBuilder;
use HTML::WikiConverter::Normalizer;
my $tree = new HTML::TreeBuilder();
$tree->parse( '<p><font style="font-style:italic; font-weight:bold">text</font></p>' );
my $norm = new HTML::WikiConverter::Normalizer();
$norm->normalize($tree);
# Roughly gives "<p><font><b><i>text</i></b></font></p>"
print $tree->as_HTML();
π¦ DESCRIPTION π¦
So here's the tea β β HTML::WikiConverter dialects convert HTML into wiki markup. Most of them (if not literally all, ngl) know absolutely nothing about CSS, and they do not take it into consideration when they're doing that html-to-wiki conversion. But likeβ¦ there is no good reason for, say, "<font style="font-weight:bold">text</font>" to not get converted into '''text''' in the MediaWiki dialect. Same energy for every other dialect β all of them should be able to use CSS info to produce wiki markup. periodt.
And it gets especially messy when you remember that several WYSIWYG HTML editors (looking at you, Mozilla's π) produce exactly this sort of CSS-heavy HTML. Before "HTML::WikiConverter::Normalizer" existed, this HTML would've been essentially converted to text, with all the CSS information justβ¦ ignored by "HTML::WikiConverter". π
"HTML::WikiConverter::Normalizer" dodges all of that with a few simple transformations that convert CSS styles into HTML tags. slay.
π METHODS π
π new
my $norm = new HTML::WikiConverter::Normalizer();
Constructs a new normalizer β¨
π normalize
$norm->normalize($elem);
Normalizes $elem and all its descendents, where $elem is an HTML::Element object. yes bestie, all of them. π«Ά
π SUBCLASSING π
The following methods may be useful to subclasses. (hi subclasses, love u π)
π handlers
my $handlers = $self->handlers;
Class method returning a reference to an array of handlers used to convert CSS to HTML. Each handler is a hashref that specifies the CSS properties and values to match, and the HTML tags and attributes the matched properties will be converted to.
The "type", "name", "value", and "tag" keys may be used to match an element's property or attribute. "type" may be either:
"css"β if matching a CSS property. In this case"name"must contain the name of the property, and"value"must contain the property value to match. π¨"attr"β if matching an HTML tag attribute. In this case"name"must contain the name of the attribute, and"value"must contain the attribute value to match. π·οΈ
"value" can be a whole bunch of things, and it's lowkey the most flexible part:
- a string β for an exact match
- a regex β which will be used to match against the element's property or attribute value
- a coderef β which will be passed the property or attribute value and is expected to return true on match, false otherwise
"*"β which matches any property or attribute value
A tag or list of tags can also be matched with the "tag" key, which takes either a string or an arrayref. π₯
To specify what actions the handler will take, the "new_tag", "new_attr", and "normalizer" keys are used.
"new_tag"is required and indicates the name of the tag that will be created."attribute"is optional and indicates the name of the attribute in the new tag that will take the value of the original CSS property.- If a coderef is given as the
"normalizer", it will be passed the value of the property/attribute and should return one suitable to be assigned to the new tag attribute.
no cap, "new_tag" really is required. don't skip it. π
π SEE ALSO π
CSS
π AUTHOR π
David J. Iberri, "<diberri@cpan.org>"
π BUGS π
Please report any bugs or feature requests to "bug-html-wikiconverter at rt.cpan.org", or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=HTML-WikiConverter>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. fr fr, the loop closes. π
π COPYRIGHT & LICENSE π
Copyright 2006 David J. Iberri, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
and that's the whole page, bestie π«Ά this was pulled from perl v5.34.0, dated 2022-06-14 β documented under HTML::...malizer(3pm), mwah πβ¨
π¦ where this page comes from
- debian bookworm: libhtml-wikiconverter-perl 0.68-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libhtml-wikiconverter-perl 0.68-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libhtml-wikiconverter-perl 0.68-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libhtml-wikiconverter-perl 0.68-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libhtml-wikiconverter-perl 0.68-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms