| 1 |
NAME |
| 2 |
HTML::HTML5::Sanity - make HTML5 DOM trees less insane |
| 3 |
|
| 4 |
SYNOPSIS |
| 5 |
use HTML::HTML5::Parser; |
| 6 |
use HTML::HTML5::Sanity; |
| 7 |
|
| 8 |
my $parser = HTML::HTML5::Parser->new; |
| 9 |
my $html5_dom = $parser->parse_file('http://example.com/'); |
| 10 |
my $sane_dom = fix_document($html5_dom); |
| 11 |
|
| 12 |
DESCRIPTION |
| 13 |
The Document Object Model (DOM) generated by HTML::HTML5::Parser meets the |
| 14 |
requirements of the HTML5 spec, but will probably catch a lot of people by |
| 15 |
surprise. |
| 16 |
|
| 17 |
The main oddity is that elements and attributes which appear to be |
| 18 |
namespaced are not really. For example, the following element: |
| 19 |
|
| 20 |
<div xml:lang="fr">...</div> |
| 21 |
|
| 22 |
Looks like it should be parsed so that it has an attribute "lang" in the |
| 23 |
XML namespace. Not so. It will really be parsed as having the attribute |
| 24 |
"xml:lang" in the null namespace. |
| 25 |
|
| 26 |
`fix_document($document)` |
| 27 |
$sane_dom = fix_document($html5_dom); |
| 28 |
|
| 29 |
Returns a modified copy of the DOM and leaving the original DOM |
| 30 |
unmodified. |
| 31 |
|
| 32 |
`fix_element($element_node, $new_document_node, \%namespaces)` |
| 33 |
Don't use this. Not exported. |
| 34 |
|
| 35 |
`fix_attribute($attribute_node, $new_element_node, \%namespaces)` |
| 36 |
Don't use this. Not exported. |
| 37 |
|
| 38 |
$HTML::HTML5::Sanity::FIX_LANG_ATTRIBUTES |
| 39 |
$HTML::HTML5::Sanity::FIX_LANG_ATTRIBUTES = 2; |
| 40 |
$sane_dom = fix_document($html5_dom); |
| 41 |
|
| 42 |
If set to 1 (the default), the package will detect invalid values in |
| 43 |
@lang and @xml:lang, and remove the attribute if it is invalid. If set |
| 44 |
to 2, it will also attempt to canonicalise the value (e.g. 'EN_GB' |
| 45 |
will be converted to to 'en-GB'). If set to 0, then the value of |
| 46 |
language attributes is not checked. |
| 47 |
|
| 48 |
BUGS |
| 49 |
Please report any bugs to <http://rt.cpan.org/>. |
| 50 |
|
| 51 |
SEE ALSO |
| 52 |
HTML::HTML5::Parser, XML::LibXML, Task::HTML5. |
| 53 |
|
| 54 |
AUTHOR |
| 55 |
Toby Inkster <[email protected]>. |
| 56 |
|
| 57 |
COPYRIGHT AND LICENSE |
| 58 |
Copyright (C) 2009-2014 by Toby Inkster |
| 59 |
|
| 60 |
This library is free software; you can redistribute it and/or modify it |
| 61 |
under the same terms as Perl itself. |
| 62 |
|
| 63 |
DISCLAIMER OF WARRANTIES |
| 64 |
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED |
| 65 |
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
| 66 |
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
| 67 |
|