Section: User Contributed Perl Documentation (3)
HTML::WikiConverter::Normalizer - Convert CSS styles to (roughly) corresponding HTML
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();
HTML::WikiConverter dialects convert HTML
into wiki markup. Most(if not all) know nothing about CSS
, nor do they take it intoconsideration when performing html-to-wiki conversion. But there is nogood reason for, say, "<fontstyle="font-weight:bold">text</font>"
not to be convertedinto '''text'''
in the MediaWiki dialect. The same is true of otherdialects, all of which should be able to use CSS
information toproduce wiki markup.
The issue becomes especially problematic when considering that severalWYSIWYG HTML editors (e.g. Mozilla's) produce this sort of CSS-heavyHTML. Prior to "HTML::WikiConverter::Normalizer", this HTML wouldhave been essentially converted to text, the CSS information havingbeen ignored by "HTML::WikiConverter".
"HTML::WikiConverter::Normalizer" avoids this with a few simpletransformations that convert CSS styles into HTML tags.
my $norm = new HTML::WikiConverter::Normalizer();
Constructs a new normalizer
Normalizes $elem and all its descendents, where $elem is anHTML::Element object.
The following methods may be useful to subclasses.
my $handlers = $self->handlers;
Class method returning reference to an array of handlers used toconvert CSS to HTML. Each handler is a hashref that specifies the CSSproperties and values to match, and the HTML tags and attributes thematched properties will be converted to.
The "type", "name", "value", and "tag" keys may be used to matchan element's property or attribute. "type" may be either "css" ifmatching a CSS property (in which case "name" must contain the nameof the property, and "value" must contain the property value tomatch) or "attr" if matching an HTML tag attribute (in which case"name" must contain the name of the attribute, and "value" mustcontain the attribute value to match).
"value" may be a string (for an exact match), regex (which will beused to match against the element's property or attribute value),coderef (which will be passed the property or attribute value and isexpected to return true on match, false otherwise), or "*" (whichmatches any property or attribute value). A tag or list of tags canalso be matched with the "tag" key, which takes either a string or anarrayref.
To specify what actions the handler will take, the "new_tag","new_attr", and "normalizer" keys are used. "new_tag" is requiredand indicates the name of the tag that will be created. "attribute"is optional and indicates the name of the attribute in the new tagthat will take the value of the original CSS property. If a coderef isgiven as the "normalizer", it will be passed the value of theproperty/attribute and should return one suitable to be assigned tothe new tag attribute.
David J. Iberri, "<diberriAATTcpan.org>"
Please report any bugs or feature requests to "bug-html-wikiconverterat 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 ofprogress on your bug as I make changes.
COPYRIGHT & LICENSE
Copyright 2006 David J. Iberri, all rights reserved.
This program is free software; you can redistribute it and/or modify itunder the same terms as Perl itself.
- SEE ALSO
- COPYRIGHT & LICENSE
This document was created byman2html,using the manual pages.