Parsoid
A bidirectional parser between wikitext and HTML5
Loading...
Searching...
No Matches
Wikimedia\Parsoid\Ext\DOMUtils Class Reference

This class provides DOM helpers useful for extensions. More...

Static Public Member Functions

static hasTypeOf (Node $node, string $type)
 Test if a node matches a given typeof.
 
static hasClass (Element $element, string $regex)
 
static matchTypeOf (Node $n, string $typeRe)
 Determine whether the node matches the given typeof attribute value.
 
static addTypeOf (Element $elt, string $type)
 Add a type to the typeof attribute.
 
static removeTypeOf (Element $elt, string $type)
 Remove a type from the typeof attribute.
 
static matchRel (Node $n, string $rel)
 Determine whether the node matches the given rel attribute value.
 
static addRel (Element $node, string $rel)
 Add a type to the rel attribute.
 
static assertElt (?Node $node)
 Assert that this is a DOM element node.
 
static migrateChildren (Node $from, Node $to, ?Node $beforeNode=null)
 Move 'from'.childNodes to 'to' adding them before 'beforeNode' If 'beforeNode' is null, the nodes are appended at the end.
 
static addAttributes (Element $elt, array $attrs)
 Add attributes to a node element.
 
static findAncestorOfName (Node $node, string $name)
 Find an ancestor of $node with nodeName $name.
 

Detailed Description

This class provides DOM helpers useful for extensions.

Member Function Documentation

◆ addAttributes()

static Wikimedia\Parsoid\Ext\DOMUtils::addAttributes ( Element $elt,
array $attrs )
static

Add attributes to a node element.

Parameters
Element$eltelement
array$attrsattributes

◆ addRel()

static Wikimedia\Parsoid\Ext\DOMUtils::addRel ( Element $node,
string $rel )
static

Add a type to the rel attribute.

This method should almost always be used instead of setAttribute, to ensure we don't overwrite existing rel information.

Parameters
Element$nodenode
string$reltype

◆ addTypeOf()

static Wikimedia\Parsoid\Ext\DOMUtils::addTypeOf ( Element $elt,
string $type )
static

Add a type to the typeof attribute.

If the elt already has an existing typeof, it makes that attribute a string of space separated types.

Parameters
Element$elt
string$typetype

◆ assertElt()

static Wikimedia\Parsoid\Ext\DOMUtils::assertElt ( ?Node $node)
static

Assert that this is a DOM element node.

This is primarily to help phan analyze variable types. @phan-assert Element $node

Parameters
?Node$node
Returns
bool Always returns true

◆ findAncestorOfName()

static Wikimedia\Parsoid\Ext\DOMUtils::findAncestorOfName ( Node $node,
string $name )
static

Find an ancestor of $node with nodeName $name.

Parameters
Node$node
string$name
Returns
?Element

◆ hasClass()

static Wikimedia\Parsoid\Ext\DOMUtils::hasClass ( Element $element,
string $regex )
static
Parameters
Element$element
string$regexPartial regular expression, e.g. "foo|bar"
Returns
bool

◆ hasTypeOf()

static Wikimedia\Parsoid\Ext\DOMUtils::hasTypeOf ( Node $node,
string $type )
static

Test if a node matches a given typeof.

Parameters
Node$nodenode
string$typetype
Returns
bool

◆ matchRel()

static Wikimedia\Parsoid\Ext\DOMUtils::matchRel ( Node $n,
string $rel )
static

Determine whether the node matches the given rel attribute value.

Parameters
Node$n
string$relExpected value of "rel" attribute, as a literal string.
Returns
?string The match if there is one, null otherwise

◆ matchTypeOf()

static Wikimedia\Parsoid\Ext\DOMUtils::matchTypeOf ( Node $n,
string $typeRe )
static

Determine whether the node matches the given typeof attribute value.

Parameters
Node$nThe node to test
string$typeReRegular expression matching the expected value of the typeof attribute.
Returns
?string The matching typeof value, or null if there is no match.

◆ migrateChildren()

static Wikimedia\Parsoid\Ext\DOMUtils::migrateChildren ( Node $from,
Node $to,
?Node $beforeNode = null )
static

Move 'from'.childNodes to 'to' adding them before 'beforeNode' If 'beforeNode' is null, the nodes are appended at the end.

Parameters
Node$fromSource node. Children will be removed.
Node$toDestination node. Children of $from will be added here
?Node$beforeNodeAdd the children before this node.

◆ removeTypeOf()

static Wikimedia\Parsoid\Ext\DOMUtils::removeTypeOf ( Element $elt,
string $type )
static

Remove a type from the typeof attribute.

Parameters
Element$elt
string$typetype

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