Parsoid
A bidirectional parser between wikitext and HTML5
|
Class for helping us traverse the DOM. More...
Public Member Functions | |
__construct (bool $traverseWithTplInfo=false, bool $applyToAttributeEmbeddedHTML=false) | |
addHandler (?string $nodeName, callable $action) | |
Add a handler to the DOM traverser. | |
traverse (?ParsoidExtensionAPI $extAPI, Node $workNode, ?DTState $state=null) | |
Traverse the DOM and fire the handlers that are registered. | |
Class for helping us traverse the DOM.
This class currently does a pre-order depth-first traversal. See DOMPostOrder
for post-order traversal.
Wikimedia\Parsoid\Utils\DOMTraverser::__construct | ( | bool | $traverseWithTplInfo = false, |
bool | $applyToAttributeEmbeddedHTML = false ) |
bool | $traverseWithTplInfo | |
bool | $applyToAttributeEmbeddedHTML |
Wikimedia\Parsoid\Utils\DOMTraverser::addHandler | ( | ?string | $nodeName, |
callable | $action ) |
Add a handler to the DOM traverser.
?string | $nodeName | An optional node name filter |
callable | $action | A callback, called on each node we traverse that matches nodeName. Will be called with the following parameters:
|
Wikimedia\Parsoid\Utils\DOMTraverser::traverse | ( | ?ParsoidExtensionAPI | $extAPI, |
Node | $workNode, | ||
?DTState | $state = null ) |
Traverse the DOM and fire the handlers that are registered.
Handlers can return
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.?ParsoidExtensionAPI | $extAPI | |
Node | $workNode | The starting node for the traversal. The traversal could go beyond the subtree rooted at $workNode if the handlers called during traversal return an arbitrary node elsewhere in the DOM in which case the traversal scope can be pretty much the whole DOM that $workNode is present in. This behavior would be confusing but there is nothing in the traversal code to prevent that. |
DTState | null | $state |