The manakai project

Web::HTML::Serializer

Serialization of HTML DOM

SYNOPSIS

  warn $element->inner_html;
  warn $document->inner_html;

DESCRIPTION

The Web::HTML::Serializer module provides a function that implements the fragment serialization algorithm of HTML5. It can be used to serialize an HTML Document, Element, or DocumentFragment 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 Web::DOM::Document and Web::DOM::Element modules implement the inner_html attribute for DOM Document and Element nodes.

METHODS

There are following methods:

$serializer = Web::HTML::Serializer->new

Return a new instance of the serializer.

$boolean = $serializer->scripting
$serializer->scripting ($boolean)

Get or set scripting is enabled (true) or disabled (false). This flag affects how HTML noscript element is serialized. By default scripting is disabled. (In Web browsers, scripting is enabled by default.)

$scalarref = $serializer->get_inner_html ($node)

Serialize the specified node using the HTML fragment serialization algorithm. The result is returned as a reference to the character string.

The argument must be a DOM Document, Document, or DocumentFragment.

SPECIFICATION

HTML

HTML Standard <https://html.spec.whatwg.org/#html-fragment-serialization-algorithm>.

SEE ALSO

Web::XML::Serializer.

Web::DOM::ParentNode.

AUTHOR

Wakaba <wakaba@suikawiki.org>.

LICENSE

Copyright 2007-2019 Wakaba <wakaba@suikawiki.org>.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.