Whatpm::HTML::Serializer
require Whatpm::HTML::Serializer;
## Serialize an HTML document
my $html = Whatpm::HTML::Serializer->get_inner_html ($doc);
## NOTE: $html = $doc->inner_html is preferred.
## Serialize an HTML element
my $html = Whatpm::HTML::Serializer->get_inner_html ($el);
## NOTE: $html = $el->inner_html is preferred.
## Serialize an HTML document fragment
my $html = Whatpm::HTML::Serializer->get_inner_html ($df);
The Whatpm::HTML::Serializer
module provides a function that implements the fragment serialization algorithm of HTML5. It can be used to serialize a HTML Document
or Element
node into an HTML document or fragment.
Note that the algorithm cannot be used to serialize an arbitrary DOM tree; an attempt to serialize a DOM that cannot be represented in a static HTML document (fragment) will result in an invalid document or in a document representing different DOM tree.
For example, the DOM tree:
+- Element |p|
+- Element |ul|
... cannot be represented in HTML serialization. The serialization algorithm will generate an invalid HTML fragment:
<p><ul></ul></p>
... which represents another DOM tree:
+- Element |p|
+- Element |ul|
(with "invalid </p>" error)
... without raising any error or warning. This is a limitation of the HTML serialization format and the fragment serialization algorithm.
NOTE: Usually you don't have to call this module directly, since Message::DOM::Document and Message::DOM::Element modules implement the inner_html
attribute for DOM Document
and Element
nodes.
$html = Whatpm::HTML::Serializer->get_inner_html ($node, [$onerror])
Serialize a node by the HTML fragment serialization algorithm.
The node to serialize. The node must be a DOM Document
, DocumentFragment
, or Element
node.
A reference to CODE
, which will be invoked when an error occurs. If the algorithm is required to raise an INVALID_STATE_ERR
error, i.e. if the algorithm is faced to a Node
whose type is different from any of ones supported by the algorithm, the CODE
is invoked with that Node
as an argument. It is expected for the CODE
to raise an exception. If no exception is raised, the Node
is ignored for the purpose of the algorithm.
If $onerror is omitted, an empty CODE
(which does nothing) is assumed.
A SCALAR
reference to the result of the HTML fragment serialization algorithm.
Whatpm <https://suika.suikawiki.org/www/markup/html/whatpm/readme>
.
Web Applications 1.0 - HTML fragment serialization algorithm <http://www.whatwg.org/specs/web-apps/current-work/complete.html#html-fragment-serialization-algorithm>
.
Modules Message::DOM::Document and Message::DOM::Element of manakai are implementing the inner_html
attribute using the Whatpm::HTML::Serializer
module.
Wakaba <wakaba@suikawiki.org>.
Copyright 2007-2011 Wakaba <wakaba@suikawiki.org>.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.