Class: DOMTraverser

utils/DOMTraverser~DOMTraverser(env, skipCheckIfAttached)

new DOMTraverser(env, skipCheckIfAttached)

Class for helping us traverse the DOM.

Class for helping us traverse the DOM.

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

Parameters:
Name Type Description
env MWParserEnvironment
skipCheckIfAttached boolean
Source:

Methods

addHandler(nodeName, action, contextopt)

Add a handler to the DOM traverser.

Add a handler to the DOM traverser.

Parameters:
Name Type Attributes Description
nodeName string
action traverserHandler

A callback, called on each node we traverse that matches nodeName.

context Object <optional>

A context object to use when the action is invoked.

Source:

traverse(workNode, env, options, atTopLevel, tplInfo) → {Node|null|true}

Traverse the DOM and fire the handlers that are registered.

Traverse the DOM and fire the handlers that are registered.

Handlers can return

  • the next node to process
    • aborts processing for current node, continues with returned node
    • can also be null, so returning workNode.nextSibling works even when workNode is a last child of its parent
  • true
    • continue regular processing on current node.
Parameters:
Name Type Description
workNode Node
env MWParserEnvironment
options Object
atTopLevel boolean
tplInfo Object

Template information.

Source:
Returns:
Type
Node | null | true