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

TreeBuilder is the receiver of events from the InsertionMode subclasses, and is responsible for forwarding events on to the TreeHandler, which is responsible for constructing a DOM. More...

+ Inheritance diagram for Wikimedia\RemexHtml\TreeBuilder\TreeBuilder:

Public Member Functions

 __construct (TreeHandler $handler, $options=[])
 
 startDocument (Tokenizer $tokenizer, $namespace, $name)
 Notify TreeBuilder and later pipeline stages of the start of a document.
 
Element null adjustedCurrentNode ()
 Get the adjusted current node.
 
 insertCharacters ( $text, $start, $length, $sourceStart, $sourceLength)
 Insert characters at the appropriate place for inserting a node.
 
Element insertElement ( $name, Attributes $attrs, $void, $sourceStart, $sourceLength)
 Insert an element in the HTML namespace, at the appropriate place for inserting a node.
 
Element insertForeign ( $ns, $name, Attributes $attrs, $void, $sourceStart, $sourceLength)
 Insert an element in any namespace, at the appropriate place for inserting a node.
 
Element pop ( $sourceStart, $sourceLength)
 Pop the current node from the stack of open elements, and notify the handler that we are done with that node.
 
 doctype ( $name, $public, $system, $quirks, $sourceStart, $sourceLength)
 Insert a doctype node.
 
 comment ( $place, $text, $sourceStart, $sourceLength)
 Insert a comment node.
 
 error ( $text, $pos)
 Notify the handler of an error (if ignoreErrors is not set).
 
 mergeAttributes (Element $elt, Attributes $attrs, $sourceStart, $sourceLength)
 Add attributes to an existing element.
 
 closePInButtonScope ( $pos)
 If the stack of open elements has a p element in button scope, then close a p element.
 
 checkUnclosed ( $allowed, $pos)
 Check the stack to see if there is any element which is not on the list of allowed elements.
 
 adoptionAgency ( $subject, $sourceStart, $sourceLength)
 Run the "adoption agency algorithm" (AAA) for the given subject tag name.
 
 anyOtherEndTag ( $name, $sourceStart, $sourceLength)
 Perform the steps required when "any other end tag" is encountered in the "in body" insertion mode.
 
 generateImpliedEndTags ( $name, $pos)
 Generate implied end tags, optionally with an element to exclude.
 
 generateImpliedEndTagsThoroughly ( $pos)
 Generate all implied end tags thoroughly.
 
 generateImpliedEndTagsAndPop ( $name, $sourceStart, $sourceLength)
 Generate implied end tags, with an element to exclude, and if the current element is not now the named excluded element, raise an error.
 
 popAllUpToElement (Element $elt, $sourceStart, $sourceLength)
 Pop elements from the stack until the specified element is popped.
 
 popAllUpToName ( $name, $sourceStart, $sourceLength)
 Pop elements from the stack until an element in the HTML namespace with the specified name is popped.
 
 popAllUpToNames ( $names, $sourceStart, $sourceLength)
 Pop elements from the stack until an element with one of the specified names is popped.
 
 clearStackBack ( $names, $pos)
 The "clear stack back to" algorithm used by several template insertion modes.
 
 stopParsing ( $pos)
 Take the steps required when the spec says to "stop parsing".
 
- Public Member Functions inherited from Wikimedia\RemexHtml\PropGuard
 __set ( $name, $value)
 

Public Attributes

const NO_QUIRKS = 0
 
const LIMITED_QUIRKS = 1
 
const QUIRKS = 2
 
const BEFORE = 0
 
const UNDER = 1
 
const ROOT = 2
 
 $isIframeSrcdoc
 
 $scriptingFlag
 
 $ignoreErrors
 
 $ignoreNulls
 
TreeHandler $handler
 
SimpleStack $stack
 
ActiveFormattingElements $afe
 
Tokenizer $tokenizer
 
 $isFragment = false
 
 $fragmentContext
 
Element null $headElement
 
Element null $formElement
 
 $framesetOK = true
 
 $quirks = self::NO_QUIRKS
 
 $fosterParenting = false
 
 $pendingTableCharacters = array( )
 

Additional Inherited Members

- Static Public Attributes inherited from Wikimedia\RemexHtml\PropGuard
static $armed = true
 

Detailed Description

TreeBuilder is the receiver of events from the InsertionMode subclasses, and is responsible for forwarding events on to the TreeHandler, which is responsible for constructing a DOM.

TreeBuilder contains most of the state referred to by the "tree construction" part of the HTML spec which is not handled elsewhere, such as the stack of open elements and the list of active formatting elements.

Miscellaneous helpers for InsertionMode subclasses are also in this class.

https://www.w3.org/TR/2016/REC-html51-20161101/syntax.html

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\RemexHtml\TreeBuilder\TreeBuilder::__construct ( TreeHandler $handler,
$options = [] )
Parameters
TreeHandler$handlerThe handler which receives tree mutation events
array$optionsAssociative array of options. The options are:
  • isIframeSrcdoc: True if the document is an iframe srcdoc document. Default false.
  • scriptingFlag: True if the scripting flag is enabled. Default true. Setting this to false cause the contents of <noscript> elements to be processed as normal content. The scriptingFlag option in the Tokenizer should be set to the same value.
  • ignoreErrors: True to ignore errors. This improves performance. Default false.
  • ignoreNulls: True to ignore null characters in the input, instead of following the specified behaviour. Default false.
  • scopeCache: True to use an implementation of the stack of open elements which caches "in scope" predicates. False to use a simpler implementation. Default true. Setting this to false may improve performance for simple documents, although at the expense of O(N^2) instead of O(N) worst case time order.

Member Function Documentation

◆ adjustedCurrentNode()

Element null Wikimedia\RemexHtml\TreeBuilder\TreeBuilder::adjustedCurrentNode ( )

Get the adjusted current node.

Returns
Element|null

◆ adoptionAgency()

Wikimedia\RemexHtml\TreeBuilder\TreeBuilder::adoptionAgency ( $subject,
$sourceStart,
$sourceLength )

Run the "adoption agency algorithm" (AAA) for the given subject tag name.

Author
C. Scott Ananian, Tim Starling
Parameters
string$subjectThe subject tag name.
int$sourceStart
int$sourceLength

◆ anyOtherEndTag()

Wikimedia\RemexHtml\TreeBuilder\TreeBuilder::anyOtherEndTag ( $name,
$sourceStart,
$sourceLength )

Perform the steps required when "any other end tag" is encountered in the "in body" insertion mode.

Parameters
string$name
int$sourceStart
int$sourceLength

◆ checkUnclosed()

Wikimedia\RemexHtml\TreeBuilder\TreeBuilder::checkUnclosed ( $allowed,
$pos )

Check the stack to see if there is any element which is not on the list of allowed elements.

Raise an error if any are found.

Parameters
array$allowedAn array with the HTML element names in the key
int$pos

◆ clearStackBack()

Wikimedia\RemexHtml\TreeBuilder\TreeBuilder::clearStackBack ( $names,
$pos )

The "clear stack back to" algorithm used by several template insertion modes.

Similar to popAllUpToName(), except that the named element is not popped, and a set of names is used instead of a single name.

Parameters
array$names
int$pos

◆ closePInButtonScope()

Wikimedia\RemexHtml\TreeBuilder\TreeBuilder::closePInButtonScope ( $pos)

If the stack of open elements has a p element in button scope, then close a p element.

The above phrase appears many times in the spec.

Parameters
int$posThe source position

◆ comment()

Wikimedia\RemexHtml\TreeBuilder\TreeBuilder::comment ( $place,
$text,
$sourceStart,
$sourceLength )

Insert a comment node.

Parameters
array | null$placeThe place where the node is to be inserted. May be either a preposition/refNode pair or null. If it is null, the node will be inserted at the "appropriate place".
string$textThe comment contents
int$sourceStart
int$sourceLength

◆ doctype()

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

Insert a doctype node.

Parameters
string$nameThe doctype name
string$publicThe public ID
string$systemThe system ID
int$quirksThe quirks mode. May be either self::NO_QUIRKS, self::LIMITED_QUIRKS or self::QUIRKS to indicate no-quirks mode, limited-quirks mode or quirks mode respectively.
int$sourceStart
int$sourceLength

◆ error()

Wikimedia\RemexHtml\TreeBuilder\TreeBuilder::error ( $text,
$pos )

Notify the handler of an error (if ignoreErrors is not set).

Parameters
string$textThe error message
int$posThe input position

◆ generateImpliedEndTags()

Wikimedia\RemexHtml\TreeBuilder\TreeBuilder::generateImpliedEndTags ( $name,
$pos )

Generate implied end tags, optionally with an element to exclude.

Parameters
string | false$nameThe name to exclude
int$posThe source position

◆ generateImpliedEndTagsAndPop()

Wikimedia\RemexHtml\TreeBuilder\TreeBuilder::generateImpliedEndTagsAndPop ( $name,
$sourceStart,
$sourceLength )

Generate implied end tags, with an element to exclude, and if the current element is not now the named excluded element, raise an error.

Then, pop all elements until an element with the name is popped from the list.

Parameters
string$nameThe name to exclude
int$sourceStart
int$sourceLength

◆ generateImpliedEndTagsThoroughly()

Wikimedia\RemexHtml\TreeBuilder\TreeBuilder::generateImpliedEndTagsThoroughly ( $pos)

Generate all implied end tags thoroughly.

This was introduced in HTML 5.1 in order to expand the set of elements which can be implicitly closed by a </template>.

Parameters
int$pos

◆ insertCharacters()

Wikimedia\RemexHtml\TreeBuilder\TreeBuilder::insertCharacters ( $text,
$start,
$length,
$sourceStart,
$sourceLength )

Insert characters at the appropriate place for inserting a node.

Parameters
string$textThe string which contains the emitted characters
int$startThe start of the range within $text to use
int$lengthThe length of the range within $text to use
int$sourceStartThe input position
int$sourceLengthThe input length

◆ insertElement()

Element Wikimedia\RemexHtml\TreeBuilder\TreeBuilder::insertElement ( $name,
Attributes $attrs,
$void,
$sourceStart,
$sourceLength )

Insert an element in the HTML namespace, at the appropriate place for inserting a node.

Parameters
string$nameThe element name
Attributes$attrsThe element attributes
bool$voidThe void (self-closing) element hint
int$sourceStartThe input position
int$sourceLengthThe input length
Returns
Element

◆ insertForeign()

Element Wikimedia\RemexHtml\TreeBuilder\TreeBuilder::insertForeign ( $ns,
$name,
Attributes $attrs,
$void,
$sourceStart,
$sourceLength )

Insert an element in any namespace, at the appropriate place for inserting a node.

Parameters
string$nsThe namespace
string$nameThe element name
Attributes$attrsThe element attributes
bool$voidThe void (self-closing) element hint
int$sourceStartThe input position
int$sourceLengthThe input length
Returns
Element

◆ mergeAttributes()

Wikimedia\RemexHtml\TreeBuilder\TreeBuilder::mergeAttributes ( Element $elt,
Attributes $attrs,
$sourceStart,
$sourceLength )

Add attributes to an existing element.

Parameters
Element$elt
Attributes$attrs
int$sourceStart
int$sourceLength

◆ pop()

Element Wikimedia\RemexHtml\TreeBuilder\TreeBuilder::pop ( $sourceStart,
$sourceLength )

Pop the current node from the stack of open elements, and notify the handler that we are done with that node.

Parameters
int$sourceStart
int$sourceLength
Returns
Element

◆ popAllUpToElement()

Wikimedia\RemexHtml\TreeBuilder\TreeBuilder::popAllUpToElement ( Element $elt,
$sourceStart,
$sourceLength )

Pop elements from the stack until the specified element is popped.

Parameters
Element$elt
int$sourceStart
int$sourceLength

◆ popAllUpToName()

Wikimedia\RemexHtml\TreeBuilder\TreeBuilder::popAllUpToName ( $name,
$sourceStart,
$sourceLength )

Pop elements from the stack until an element in the HTML namespace with the specified name is popped.

Parameters
string$name
int$sourceStart
int$sourceLength

◆ popAllUpToNames()

Wikimedia\RemexHtml\TreeBuilder\TreeBuilder::popAllUpToNames ( $names,
$sourceStart,
$sourceLength )

Pop elements from the stack until an element with one of the specified names is popped.

Parameters
array$namesAn array with the allowed names in the keys
int$sourceStart
int$sourceLength

◆ startDocument()

Wikimedia\RemexHtml\TreeBuilder\TreeBuilder::startDocument ( Tokenizer $tokenizer,
$namespace,
$name )

Notify TreeBuilder and later pipeline stages of the start of a document.

This is called by the Dispatcher when a startDocument event is received.

Parameters
Tokenizer$tokenizer
string$namespace
string$name

◆ stopParsing()

Wikimedia\RemexHtml\TreeBuilder\TreeBuilder::stopParsing ( $pos)

Take the steps required when the spec says to "stop parsing".

This occurs when an end-of-file token is received, and is equivalent to the endDocument() methods elsewhere.

Parameters
int$pos

Member Data Documentation

◆ $afe

ActiveFormattingElements Wikimedia\RemexHtml\TreeBuilder\TreeBuilder::$afe

◆ $formElement

Element null Wikimedia\RemexHtml\TreeBuilder\TreeBuilder::$formElement

◆ $handler

TreeHandler Wikimedia\RemexHtml\TreeBuilder\TreeBuilder::$handler

◆ $headElement

Element null Wikimedia\RemexHtml\TreeBuilder\TreeBuilder::$headElement

◆ $stack

SimpleStack Wikimedia\RemexHtml\TreeBuilder\TreeBuilder::$stack

◆ $tokenizer

Tokenizer Wikimedia\RemexHtml\TreeBuilder\TreeBuilder::$tokenizer

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