A bidirectional parser between wikitext and HTML5
Parsoid\Utils\DOMTraverser Class Reference

Class for helping us traverse the DOM. More...

+ Inheritance diagram for Parsoid\Utils\DOMTraverser:

Public Member Functions

 addHandler (?string $nodeName, callable $action)
 Add a handler to the DOM traverser. More...
 traverse (DOMNode $workNode, Env $env, array $options=[], bool $atTopLevel=false, ?stdClass $tplInfo=null)
 Traverse the DOM and fire the handlers that are registered. More...

Detailed Description

Class for helping us traverse the DOM.

This class currently does a pre-order depth-first traversal. See DOMPostOrder for post-order traversal.

Member Function Documentation

◆ addHandler()

Parsoid\Utils\DOMTraverser::addHandler ( ?string  $nodeName,
callable  $action 

Add a handler to the DOM traverser.

string | null$nodeNameAn optional node name filter
callable$actionA callback, called on each node we traverse that matches nodeName. Will be called with the following parameters:
  • DOMNode $node: the node being processed
  • Env $env: the parser environment
  • bool $atTopLevel: passed through from DOMTraverser::traverse
  • stdClass $tplInfo: Template information. See traverse(). Return value: DOMNode|null|true.
  • true: proceed normally
  • DOMNode: traversal will continue on the new node (further handlers will not be called on the current node); after processing it and its siblings, it will continue with the next sibling of the closest ancestor which has one.
  • null: like the DOMNode case, except there is no new node to process before continuing.

◆ traverse()

Parsoid\Utils\DOMTraverser::traverse ( DOMNode  $workNode,
Env  $env,
array  $options = [],
bool  $atTopLevel = false,
?stdClass  $tplInfo = null 

Traverse the DOM and fire the handlers that are registered.

Handlers can return

  • the next node to process: aborts processing for current node (ie. no further handlers are called) and continues processing on returned node. Essentially, that node and its siblings replace the current node and its siblings for the purposes of the traversal; after they are fully processed, the algorithm moves back to the parent of $workNode to look for the next sibling.
  • null: same as above, except it continues from the next sibling of the parent (or if that does not exist, the next sibling of the grandparent etc). This is so that returning $workNode->nextSibling works even when workNode is a last child of its parent.
  • true: continues regular processing on current node.
DOMNode$workNodeThe root node for the traversal.
stdClass | null$tplInfoTemplate information. When set, it must have all of these fields:
  • first: (DOMNode) first sibling
  • last: (DOMNode) last sibling
  • dsr: field from Pasoid ino
  • clear: when set, the template will not be passed along for further processing

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