1HTML::WikiConverter::NoUrsmearliCzoenrt(r3i)buted Perl DHoTcMuLm:e:nWtiaktiiCoonnverter::Normalizer(3)
2
3
4
6 HTML::WikiConverter::Normalizer - Convert CSS styles to (roughly)
7 corresponding HTML
8
10 use HTML::TreeBuilder;
11 use HTML::WikiConverter::Normalizer;
12
13 my $tree = new HTML::TreeBuilder();
14 $tree->parse( '<p><font style="font-style:italic; font-weight:bold">text</font></p>' );
15
16 my $norm = new HTML::WikiConverter::Normalizer();
17 $norm->normalize($tree);
18
19 # Roughly gives "<p><font><b><i>text</i></b></font></p>"
20 print $tree->as_HTML();
21
23 HTML::WikiConverter dialects convert HTML into wiki markup. Most (if
24 not all) know nothing about CSS, nor do they take it into consideration
25 when performing html-to-wiki conversion. But there is no good reason
26 for, say, "<font style="font-weight:bold">text</font>" not to be
27 converted into '''text''' in the MediaWiki dialect. The same is true of
28 other dialects, all of which should be able to use CSS information to
29 produce wiki markup.
30
31 The issue becomes especially problematic when considering that several
32 WYSIWYG HTML editors (e.g. Mozilla's) produce this sort of CSS-heavy
33 HTML. Prior to "HTML::WikiConverter::Normalizer", this HTML would have
34 been essentially converted to text, the CSS information having been
35 ignored by "HTML::WikiConverter".
36
37 "HTML::WikiConverter::Normalizer" avoids this with a few simple
38 transformations that convert CSS styles into HTML tags.
39
41 new
42 my $norm = new HTML::WikiConverter::Normalizer();
43
44 Constructs a new normalizer
45
46 normalize
47 $norm->normalize($elem);
48
49 Normalizes $elem and all its descendents, where $elem is an
50 HTML::Element object.
51
53 The following methods may be useful to subclasses.
54
55 handlers
56 my $handlers = $self->handlers;
57
58 Class method returning reference to an array of handlers used to
59 convert CSS to HTML. Each handler is a hashref that specifies the CSS
60 properties and values to match, and the HTML tags and attributes the
61 matched properties will be converted to.
62
63 The "type", "name", "value", and "tag" keys may be used to match an
64 element's property or attribute. "type" may be either "css" if matching
65 a CSS property (in which case "name" must contain the name of the
66 property, and "value" must contain the property value to match) or
67 "attr" if matching an HTML tag attribute (in which case "name" must
68 contain the name of the attribute, and "value" must contain the
69 attribute value to match).
70
71 "value" may be a string (for an exact match), regex (which will be used
72 to match against the element's property or attribute value), coderef
73 (which will be passed the property or attribute value and is expected
74 to return true on match, false otherwise), or "*" (which matches any
75 property or attribute value). A tag or list of tags can also be matched
76 with the "tag" key, which takes either a string or an arrayref.
77
78 To specify what actions the handler will take, the "new_tag",
79 "new_attr", and "normalizer" keys are used. "new_tag" is required and
80 indicates the name of the tag that will be created. "attribute" is
81 optional and indicates the name of the attribute in the new tag that
82 will take the value of the original CSS property. If a coderef is given
83 as the "normalizer", it will be passed the value of the
84 property/attribute and should return one suitable to be assigned to the
85 new tag attribute.
86
88 CSS
89
91 David J. Iberri, "<diberri@cpan.org>"
92
94 Please report any bugs or feature requests to "bug-html-wikiconverter
95 at rt.cpan.org", or through the web interface at
96 <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=HTML-WikiConverter>. I
97 will be notified, and then you'll automatically be notified of progress
98 on your bug as I make changes.
99
101 Copyright 2006 David J. Iberri, all rights reserved.
102
103 This program is free software; you can redistribute it and/or modify it
104 under the same terms as Perl itself.
105
106
107
108perl v5.36.0 2022-07-22HTML::WikiConverter::Normalizer(3)