Parsoid
A bidirectional parser between wikitext and HTML5
Loading...
Searching...
No Matches
Wikimedia\Parsoid\Wt2Html\XMLSerializer Class Reference

Stand-alone XMLSerializer for DOM3 documents. More...

Static Public Member Functions

static serialize (Node $node, array $options=[])
 Serialize an HTML DOM3 node to an XHTML string.
 

Detailed Description

Stand-alone XMLSerializer for DOM3 documents.

The output is identical to standard XHTML5 DOM serialization, as given by http://www.w3.org/TR/html-polyglot/ and https://html.spec.whatwg.org/multipage/syntax.html#serialising-html-fragments except that we may quote attributes with single quotes, only where that would result in more compact output than the standard double-quoted serialization.

Member Function Documentation

◆ serialize()

static Wikimedia\Parsoid\Wt2Html\XMLSerializer::serialize ( Node $node,
array $options = [] )
static

Serialize an HTML DOM3 node to an XHTML string.

Parameters
Node$node
array$options
  • smartQuote (bool, default true): use single quotes for attributes when that's less escaping
  • innerXML (bool, default false): only serialize the contents of $node, exclude $node itself
  • captureOffsets (bool, default false): return tag position data (see below)
  • addDoctype (bool, default true): prepend a DOCTYPE when a full HTML document is serialized
  • saveData (bool, default false): Copy the NodeData into JSON attributes. This is for debugging purposes only, the normal code path is to use DOMDataUtils::storeDataAttribs().
  • keepTmp (bool, default false): When saving data, include DataParsoid::$tmp.
Returns
array An array with the following data:
  • html: the serialized HTML
  • offsets: the start and end position of each element in the HTML, in a [ $uid => [ 'html' => [ $start, $end ] ], ... ] format where $uid is the element's Parsoid ID, $start is the 0-based index of the first character of the element and $end is the index of the first character of the opening tag of the next sibling element, or the index of the last character of the element's closing tag if there is no next sibling. The positions are relative to the end of the opening <body> tag (the DOCTYPE header is not counted), and only present when the captureOffsets flag is set.

The documentation for this class was generated from the following file: