RemexHtml
Fast HTML 5 parser
Loading...
Searching...
No Matches
Wikimedia\RemexHtml\DOM\DOMSerializer Class Reference

This class providers a Serializer-like interface to DOMBuilder, allowing DOMBuilder and direct serialization to be used interchangeably. More...

+ Inheritance diagram for Wikimedia\RemexHtml\DOM\DOMSerializer:

Public Member Functions

 __construct (DOMBuilder $builder, DOMFormatter $formatter)
 
 getResult ()
 Get the serialized result of tree construction.
Returns
string

 
 startDocument ( $fragmentNamespace, $fragmentName)
 Called when parsing starts.
Parameters
string | null$fragmentNamespaceThe fragment namespace, or null to run in document mode.
string | null$fragmentNameThe fragment tag name, or null to run in document mode.

 
 endDocument ( $pos)
 Called when parsing stops.
Parameters
int$posThe input string length, i.e. the past-the-end position.

 
 characters ( $preposition, $refElement, $text, $start, $length, $sourceStart, $sourceLength)
 Insert characters.
Parameters
int$prepositionThe placement of the new node with respect to $ref. May be TreeBuilder::
  • BEFORE: insert as a sibling before the reference element
  • UNDER: append as the last child of the reference element
  • ROOT: append as the last child of the document node
Element | null$refInsert before/below this element, or null if $preposition is ROOT.
string$textThe text to insert is a substring of this string, with the start and length of the substring given by $start and $length. We do it this way to avoid unnecessary copying.
int$startThe start of the substring
int$lengthThe length of the substring
int$sourceStartThe input position. This is not necessarily accurate, particularly when the tokenizer is run without ignoreEntities, or in CDATA sections.
int$sourceLengthThe length of the input which is consumed. The same caveats apply as for $sourceStart.

 
 insertElement ( $preposition, $refElement, Element $element, $void, $sourceStart, $sourceLength)
 Insert an element.The element name and attributes are given in the supplied Element object. Handlers for this event typically attach an identifier to the userData property of the Element object, to identify the element when it is used again in subsequent tree mutations.
Parameters
int$prepositionThe placement of the new node with respect to $ref. May be TreeBuilder::
  • BEFORE: insert as a sibling before the reference element
  • UNDER: append as the last child of the reference element
  • ROOT: append as the last child of the document node
Element | null$refInsert before/below this element, or null if $preposition is ROOT.
Element$elementAn object containing information about the new element. The same object will be used for $parent and $refNode in other calls as appropriate. The handler can set $element->userData to attach a suitable DOM object to identify the mutation target in subsequent calls.
bool$voidTrue if this is a void element which cannot have any children appended to it. This is usually true if the element is closed by the same token that opened it. No endTag() event will be sent for such an element. This is only true if self-closing tags are acknowledged for this tag name, so it is a hint to the serializer that a self-closing tag is acceptable.
int$sourceStartThe input position
int$sourceLengthThe length of the input which is consumed

 
 endTag (Element $element, $sourceStart, $sourceLength)
 A hint that an element was closed and was removed from the stack of open elements.It probably won't be mutated again.
Parameters
Element$elementThe element being ended
int$sourceStartThe input position
int$sourceLengthThe length of the input which is consumed

 
 doctype ( $name, $public, $system, $quirks, $sourceStart, $sourceLength)
 A valid DOCTYPE token was found.
Parameters
string$nameThe doctype name, usually "html"
string$publicThe PUBLIC identifier
string$systemThe SYSTEM identifier
int$quirksThe quirks mode implied from the doctype. One of:
  • TreeBuilder::NO_QUIRKS : no quirks
  • TreeBuilder::LIMITED_QUIRKS : limited quirks
  • TreeBuilder::QUIRKS : full quirks
int$sourceStartThe input position
int$sourceLengthThe length of the input which is consumed

 
 comment ( $preposition, $refElement, $text, $sourceStart, $sourceLength)
 Insert a comment.
Parameters
int$prepositionThe placement of the new node with respect to $ref. May be TreeBuilder::
  • BEFORE: insert as a sibling before the reference element
  • UNDER: append as the last child of the reference element
  • ROOT: append as the last child of the document node
Element | null$refInsert before/below this element, or null if $preposition is ROOT.
string$textThe text of the comment
int$sourceStartThe input position
int$sourceLengthThe length of the input which is consumed

 
 error ( $text, $pos)
 A parse error.
Parameters
string$textAn error message explaining in English what the author did wrong, and what the parser intends to do about the situation.
int$posThe input position at which the error occurred

 
 mergeAttributes (Element $element, Attributes $attrs, $sourceStart)
 Add attributes to an existing element.This is used to update the attributes of the <html> or <body> elements. The event receiver should add only those attributes which the original element does not already have. It should not overwrite existing attributes.
Parameters
Element$elementThe element to update
Attributes$attrsThe new attributes to add
int$sourceStartThe input position

 
 removeNode (Element $element, $sourceStart)
 Remove a node from the tree, and all its children.This is only done when a <frameset> element is found, which triggers removal of the partially-constructed body element.
Parameters
Element$elementThe element to remove
int$sourceStartThe location in the source at which this action was triggered.

 
 reparentChildren (Element $element, Element $newParent, $sourceStart)
 Take all children of a given parent $element, and insert them as children of $newParent, removing them from their original parent in the process.Insert $newParent as now the only child of $element.
Parameters
Element$elementThe old parent element
Element$newParentThe new parent element
int$sourceStartThe location in the source at which this action was triggered.

 

Detailed Description

This class providers a Serializer-like interface to DOMBuilder, allowing DOMBuilder and direct serialization to be used interchangeably.

HtmlFormatter::formatDOMNode() can be used directly if this interface is not required.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\RemexHtml\DOM\DOMSerializer::__construct ( DOMBuilder $builder,
DOMFormatter $formatter )
Parameters
DOMBuilder$builder
DOMFormatter$formatterThis may be, for example, an HtmlFormatter object

Member Function Documentation

◆ characters()

Wikimedia\RemexHtml\DOM\DOMSerializer::characters ( $preposition,
$refElement,
$text,
$start,
$length,
$sourceStart,
$sourceLength )

Insert characters.

Parameters
int$prepositionThe placement of the new node with respect to $ref. May be TreeBuilder::
  • BEFORE: insert as a sibling before the reference element
  • UNDER: append as the last child of the reference element
  • ROOT: append as the last child of the document node
Element | null$refInsert before/below this element, or null if $preposition is ROOT.
string$textThe text to insert is a substring of this string, with the start and length of the substring given by $start and $length. We do it this way to avoid unnecessary copying.
int$startThe start of the substring
int$lengthThe length of the substring
int$sourceStartThe input position. This is not necessarily accurate, particularly when the tokenizer is run without ignoreEntities, or in CDATA sections.
int$sourceLengthThe length of the input which is consumed. The same caveats apply as for $sourceStart.

Implements Wikimedia\RemexHtml\TreeBuilder\TreeHandler.

◆ comment()

Wikimedia\RemexHtml\DOM\DOMSerializer::comment ( $preposition,
$refElement,
$text,
$sourceStart,
$sourceLength )

Insert a comment.

Parameters
int$prepositionThe placement of the new node with respect to $ref. May be TreeBuilder::
  • BEFORE: insert as a sibling before the reference element
  • UNDER: append as the last child of the reference element
  • ROOT: append as the last child of the document node
Element | null$refInsert before/below this element, or null if $preposition is ROOT.
string$textThe text of the comment
int$sourceStartThe input position
int$sourceLengthThe length of the input which is consumed

Implements Wikimedia\RemexHtml\TreeBuilder\TreeHandler.

◆ doctype()

Wikimedia\RemexHtml\DOM\DOMSerializer::doctype ( $name,
$public,
$system,
$quirks,
$sourceStart,
$sourceLength )

A valid DOCTYPE token was found.

Parameters
string$nameThe doctype name, usually "html"
string$publicThe PUBLIC identifier
string$systemThe SYSTEM identifier
int$quirksThe quirks mode implied from the doctype. One of:
  • TreeBuilder::NO_QUIRKS : no quirks
  • TreeBuilder::LIMITED_QUIRKS : limited quirks
  • TreeBuilder::QUIRKS : full quirks
int$sourceStartThe input position
int$sourceLengthThe length of the input which is consumed

Implements Wikimedia\RemexHtml\TreeBuilder\TreeHandler.

◆ endDocument()

Wikimedia\RemexHtml\DOM\DOMSerializer::endDocument ( $pos)

Called when parsing stops.

Parameters
int$posThe input string length, i.e. the past-the-end position.

Implements Wikimedia\RemexHtml\TreeBuilder\TreeHandler.

◆ endTag()

Wikimedia\RemexHtml\DOM\DOMSerializer::endTag ( Element $element,
$sourceStart,
$sourceLength )

A hint that an element was closed and was removed from the stack of open elements.It probably won't be mutated again.

Parameters
Element$elementThe element being ended
int$sourceStartThe input position
int$sourceLengthThe length of the input which is consumed

Implements Wikimedia\RemexHtml\TreeBuilder\TreeHandler.

◆ error()

Wikimedia\RemexHtml\DOM\DOMSerializer::error ( $text,
$pos )

A parse error.

Parameters
string$textAn error message explaining in English what the author did wrong, and what the parser intends to do about the situation.
int$posThe input position at which the error occurred

Implements Wikimedia\RemexHtml\TreeBuilder\TreeHandler.

◆ getResult()

Wikimedia\RemexHtml\DOM\DOMSerializer::getResult ( )

Get the serialized result of tree construction.

Returns
string

Implements Wikimedia\RemexHtml\Serializer\AbstractSerializer.

◆ insertElement()

Wikimedia\RemexHtml\DOM\DOMSerializer::insertElement ( $preposition,
$refElement,
Element $element,
$void,
$sourceStart,
$sourceLength )

Insert an element.The element name and attributes are given in the supplied Element object. Handlers for this event typically attach an identifier to the userData property of the Element object, to identify the element when it is used again in subsequent tree mutations.

Parameters
int$prepositionThe placement of the new node with respect to $ref. May be TreeBuilder::
  • BEFORE: insert as a sibling before the reference element
  • UNDER: append as the last child of the reference element
  • ROOT: append as the last child of the document node
Element | null$refInsert before/below this element, or null if $preposition is ROOT.
Element$elementAn object containing information about the new element. The same object will be used for $parent and $refNode in other calls as appropriate. The handler can set $element->userData to attach a suitable DOM object to identify the mutation target in subsequent calls.
bool$voidTrue if this is a void element which cannot have any children appended to it. This is usually true if the element is closed by the same token that opened it. No endTag() event will be sent for such an element. This is only true if self-closing tags are acknowledged for this tag name, so it is a hint to the serializer that a self-closing tag is acceptable.
int$sourceStartThe input position
int$sourceLengthThe length of the input which is consumed

Implements Wikimedia\RemexHtml\TreeBuilder\TreeHandler.

◆ mergeAttributes()

Wikimedia\RemexHtml\DOM\DOMSerializer::mergeAttributes ( Element $element,
Attributes $attrs,
$sourceStart )

Add attributes to an existing element.This is used to update the attributes of the <html> or <body> elements. The event receiver should add only those attributes which the original element does not already have. It should not overwrite existing attributes.

Parameters
Element$elementThe element to update
Attributes$attrsThe new attributes to add
int$sourceStartThe input position

Implements Wikimedia\RemexHtml\TreeBuilder\TreeHandler.

◆ removeNode()

Wikimedia\RemexHtml\DOM\DOMSerializer::removeNode ( Element $element,
$sourceStart )

Remove a node from the tree, and all its children.This is only done when a <frameset> element is found, which triggers removal of the partially-constructed body element.

Parameters
Element$elementThe element to remove
int$sourceStartThe location in the source at which this action was triggered.

Implements Wikimedia\RemexHtml\TreeBuilder\TreeHandler.

◆ reparentChildren()

Wikimedia\RemexHtml\DOM\DOMSerializer::reparentChildren ( Element $element,
Element $newParent,
$sourceStart )

Take all children of a given parent $element, and insert them as children of $newParent, removing them from their original parent in the process.Insert $newParent as now the only child of $element.

Parameters
Element$elementThe old parent element
Element$newParentThe new parent element
int$sourceStartThe location in the source at which this action was triggered.

Implements Wikimedia\RemexHtml\TreeBuilder\TreeHandler.

◆ startDocument()

Wikimedia\RemexHtml\DOM\DOMSerializer::startDocument ( $fragmentNamespace,
$fragmentName )

Called when parsing starts.

Parameters
string | null$fragmentNamespaceThe fragment namespace, or null to run in document mode.
string | null$fragmentNameThe fragment tag name, or null to run in document mode.

Implements Wikimedia\RemexHtml\TreeBuilder\TreeHandler.


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