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

These helpers pertain to HTML and data attributes of a node. More...

Static Public Member Functions

static getBag (Document $doc)
 Return the dynamic "bag" property of a Document.
 
static getCodec (Node $node)
 Return the JsonCodec used for rich attributes in a Document.
 
static isPreparedAndLoaded (Document $doc)
 
static prepareAndLoadDoc (Document $doc, array $options=[])
 
static storeAndUnprepareDoc (Document $doc, array $options)
 
static stashObjectInDoc (Document $doc, NodeData $obj)
 Stash $obj in $doc and return an id for later retrieval.
 
static eagerlyLoadRichAttributes (Element $node)
 
static hasInlineRichAttributes (Element $node)
 
static dedupeNodeData (Node $clonedRoot)
 
static noAttrs (Element $node)
 Does this node have any attributes?
 
static loadFromPageBundle (Element $node)
 
static getNodeData (Element $node, bool $init=true)
 Fetch node data from the data-bag OR pagebundle.
 
static setNodeData (Element $node, NodeData $data)
 Set node data.
 
static getDataParsoid (Element $node)
 Get data parsoid info from a node.
 
static setDataParsoid (Element $node, DataParsoid $dp)
 Set data parsoid info on a node.
 
static getDataMwVariant (Element $node)
 Returns the language variant information of a node.
 
static getDataNodeI18n (Element $node)
 Retrieves internationalization (i18n) information of a node (typically for localization)
 
static setDataNodeI18n (Element $node, I18nInfo $info)
 Sets internationalization (i18n) information of a node, used for later localization.
 
static getDataAttrI18n (Element $node, string $name)
 Retrieves internationalization (i18n) information of an attribute value (typically for localization)
 
static setDataAttrI18n (Element $node, string $name, I18nInfo $info)
 Sets internationalization (i18n) information of a attribute value, used for later localization.
 
static getDataAttrI18nNames (Element $node)
 
static getDataParsoidDiff (Element $node)
 Get data diff info from a node.
 
static getDataParsoidDiffDefault (Element $node)
 Get data diff info from a node, setting a default value if not present.
 
static setDataParsoidDiff (Element $node, ?DataParsoidDiff $diffObj)
 Set data diff info on a node.
 
static getDataMw (Element $node)
 Get data meta wiki info from a node.
 
static getDataMwIfExists (Element $node)
 Get data meta wiki info, but don't create it if it doesn't exist.
 
static setDataMw (Element $node, ?DataMw $dmw)
 Set data meta wiki info from a node.
 
static getJSONAttribute (Element $node, string $name, $defaultVal)
 Get an object from a JSON-encoded XML attribute on a node.
 
static setJSONAttribute (Element $node, string $name, $obj)
 Set a attribute on a node with a JSON-encoded object.
 
static setShadowInfo (Element $node, string $name, $val)
 Set shadow info on a node; similar to the method on tokens.
 
static setShadowInfoIfModified (Element $node, string $name, $val, $origVal, bool $skipOrig=false)
 Set shadow info on a node; similar to the method on tokens.
 
static addNormalizedAttribute (Element $node, string $name, $val, $origVal, bool $skipOrig=false)
 Set an attribute and shadow info to a node.
 
static visitAndLoadDataAttribs (Node $node)
 Walk DOM from $node downward calling loadDataAttribs.
 
static usedIdIndex (SiteConfig $siteConfig, Document $doc, array $fragments=[])
 Builds an index of id attributes seen in the DOM.
 
static visitAndStoreDataAttribs (Node $node, array $options=[])
 Walk DOM from node downward calling storeDataAttribs.
 
static cloneNode (Node $elt, bool $deep)
 Clones a node and its data bag.
 
static cloneElement (Element $elt, bool $deep)
 Clones an element and its data bag(s)
 
static cloneDocumentFragment (DocumentFragment $df)
 Deep clone a DocumentFragment and its associated data bags.
 
static cloneDocument (Document $doc)
 Deep clone a Document and its associated data bags.
 
static getAttributeObject (Element $node, string $name, $classHint)
 Return the value of a rich attribute as a live (by-reference) object.
 
static getAttributeObjectDefault (Element $node, string $name, $classHint)
 Return the value of a rich attribute as a live (by-reference) object.
 
static setAttributeObject (Element $node, string $name, object $value, $classHint=null)
 Set the value of a rich attribute, overwriting any previous value.
 
static setAttributeObjectNodeData (NodeData $nodeData, string $name, object $value, $classHint=null)
 
static removeAttributeObject (Element $node, string $name)
 Remove a rich attribute.
 
static getAttributeDom (Element $node, string $name)
 Return the value of a rich attribute as a live DocumentFragment.
 
static getAttributeDomDefault (Element $node, string $name)
 Return the value of a rich attribute as a DocumentFragment, creating a new document fragment and setting the attribute if the attribute was not previously present.
 
static setAttributeDom (Element $node, string $name, DocumentFragment $value)
 Set the value of a rich attribute, overwriting any previous value.
 
static removeAttributeDom (Element $node, string $name)
 Remove a rich attribute.
 
static dumpRichAttribs (Element $node, array &$attrs, bool $keepTmp, bool $storeDiffMark)
 Modify the attribute array, replacing data-object-id with JSON encoded data.
 

Public Attributes

const DATA_OBJECT_ATTR_NAME = 'data-object-id'
 

Detailed Description

These helpers pertain to HTML and data attributes of a node.

Member Function Documentation

◆ addNormalizedAttribute()

static Wikimedia\Parsoid\Utils\DOMDataUtils::addNormalizedAttribute ( Element $node,
string $name,
$val,
$origVal,
bool $skipOrig = false )
static

Set an attribute and shadow info to a node.

Similar to the method on tokens

Parameters
Element$nodenode
string$nameName of the attribute.
mixed$valvalue
mixed$origValoriginal value
bool$skipOrig

◆ dumpRichAttribs()

static Wikimedia\Parsoid\Utils\DOMDataUtils::dumpRichAttribs ( Element $node,
array & $attrs,
bool $keepTmp,
bool $storeDiffMark )
static

Modify the attribute array, replacing data-object-id with JSON encoded data.

This is just a debugging hack, not to be confused with DOMDataUtils::storeDataAttribs(), and does not store flattened versions of attributes.

Parameters
Element$node
array&$attrs
bool$keepTmp
bool$storeDiffMark

◆ getAttributeDom()

static Wikimedia\Parsoid\Utils\DOMDataUtils::getAttributeDom ( Element $node,
string $name )
static

Return the value of a rich attribute as a live DocumentFragment.

This also serves as an assertion that there are not conflicting types.

Note
A string-valued attribute will be returned as a DocumentFragment with a single Text node. This supports the efficient serialization of 'simple' DocumentFragments as simple strings.
Parameters
Element$nodeThe node on which the attribute is to be found.
string$nameThe name of the attribute.
Returns
?DocumentFragment The attribute value, or null if not present.

◆ getAttributeDomDefault()

static Wikimedia\Parsoid\Utils\DOMDataUtils::getAttributeDomDefault ( Element $node,
string $name )
static

Return the value of a rich attribute as a DocumentFragment, creating a new document fragment and setting the attribute if the attribute was not previously present.

Parameters
Element$nodeThe node on which the attribute is to be found.
string$nameThe name of the attribute.
Returns
DocumentFragment The attribute value.

◆ getAttributeObject()

static Wikimedia\Parsoid\Utils\DOMDataUtils::getAttributeObject ( Element $node,
string $name,
$classHint )
static

Return the value of a rich attribute as a live (by-reference) object.

This also serves as an assertion that there are not conflicting types.

@template T

Parameters
Element$nodeThe node on which the attribute is to be found.
string$nameThe name of the attribute.
class-string<T>|Hint<T>$classHint
Returns
T|null The attribute value, or null if not present.

◆ getAttributeObjectDefault()

static Wikimedia\Parsoid\Utils\DOMDataUtils::getAttributeObjectDefault ( Element $node,
string $name,
$classHint )
static

Return the value of a rich attribute as a live (by-reference) object.

This also serves as an assertion that there are not conflicting types. If the value is not present, a default value will be created using $codec->defaultValue() falling back to $className::defaultValue() and stored as the value of the attribute.

Note
The $className should have be JsonCodecable (either directly or via a custom JsonClassCodec).

@template T

Parameters
Element$nodeThe node on which the attribute is to be found.
string$nameThe name of the attribute.
class-string<T>|Hint<T>$classHint
Returns
T|null The attribute value, or null if not present.

◆ getBag()

static Wikimedia\Parsoid\Utils\DOMDataUtils::getBag ( Document $doc)
static

Return the dynamic "bag" property of a Document.

Parameters
Document$doc
Returns
DataBag

◆ getCodec()

static Wikimedia\Parsoid\Utils\DOMDataUtils::getCodec ( Node $node)
static

Return the JsonCodec used for rich attributes in a Document.

Parameters
Node$node
Returns
DOMDataCodec

◆ getDataAttrI18n()

static Wikimedia\Parsoid\Utils\DOMDataUtils::getDataAttrI18n ( Element $node,
string $name )
static

Retrieves internationalization (i18n) information of an attribute value (typically for localization)

Parameters
Element$node
string$name
Returns
?I18nInfo

◆ getDataAttrI18nNames()

static Wikimedia\Parsoid\Utils\DOMDataUtils::getDataAttrI18nNames ( Element $node)
static
Parameters
Element$node
Returns
array

◆ getDataMw()

static Wikimedia\Parsoid\Utils\DOMDataUtils::getDataMw ( Element $node)
static

Get data meta wiki info from a node.

Parameters
Element$nodenode
Returns
DataMw

◆ getDataMwVariant()

static Wikimedia\Parsoid\Utils\DOMDataUtils::getDataMwVariant ( Element $node)
static

Returns the language variant information of a node.

Parameters
Element$node
Returns
?DataMwVariant

◆ getDataNodeI18n()

static Wikimedia\Parsoid\Utils\DOMDataUtils::getDataNodeI18n ( Element $node)
static

Retrieves internationalization (i18n) information of a node (typically for localization)

Parameters
Element$node
Returns
?I18nInfo

◆ getDataParsoid()

static Wikimedia\Parsoid\Utils\DOMDataUtils::getDataParsoid ( Element $node)
static

Get data parsoid info from a node.

Parameters
Element$nodenode
Returns
DataParsoid

◆ getDataParsoidDiff()

static Wikimedia\Parsoid\Utils\DOMDataUtils::getDataParsoidDiff ( Element $node)
static

Get data diff info from a node.

Parameters
Element$nodenode
Returns
?DataParsoidDiff

◆ getDataParsoidDiffDefault()

static Wikimedia\Parsoid\Utils\DOMDataUtils::getDataParsoidDiffDefault ( Element $node)
static

Get data diff info from a node, setting a default value if not present.

Parameters
Element$nodenode
Returns
DataParsoidDiff

◆ getJSONAttribute()

static Wikimedia\Parsoid\Utils\DOMDataUtils::getJSONAttribute ( Element $node,
string $name,
$defaultVal )
static

Get an object from a JSON-encoded XML attribute on a node.

Parameters
Element$nodenode
string$namename
mixed$defaultVal
Returns
mixed
Deprecated
since 0.23; use getAttributeObject()

◆ getNodeData()

static Wikimedia\Parsoid\Utils\DOMDataUtils::getNodeData ( Element $node,
bool $init = true )
static

Fetch node data from the data-bag OR pagebundle.

Initialize if not found (unless disabled via the $init param)

◆ noAttrs()

static Wikimedia\Parsoid\Utils\DOMDataUtils::noAttrs ( Element $node)
static

Does this node have any attributes?

Parameters
Element$node
Returns
bool

◆ removeAttributeDom()

static Wikimedia\Parsoid\Utils\DOMDataUtils::removeAttributeDom ( Element $node,
string $name )
static

Remove a rich attribute.

Parameters
Element$nodeThe node on which the attribute is to be found.
string$nameThe name of the attribute.

◆ removeAttributeObject()

static Wikimedia\Parsoid\Utils\DOMDataUtils::removeAttributeObject ( Element $node,
string $name )
static

Remove a rich attribute.

Parameters
Element$nodeThe node on which the attribute is to be found.
string$nameThe name of the attribute.

◆ setAttributeDom()

static Wikimedia\Parsoid\Utils\DOMDataUtils::setAttributeDom ( Element $node,
string $name,
DocumentFragment $value )
static

Set the value of a rich attribute, overwriting any previous value.

Generally mutating the result returned by the ::getAttribute*Default() methods should be done instead of using this method, since the objects returned are live.

Parameters
Element$nodeThe node on which the attribute is to be found.
string$nameThe name of the attribute.
DocumentFragment$value

◆ setAttributeObject()

static Wikimedia\Parsoid\Utils\DOMDataUtils::setAttributeObject ( Element $node,
string $name,
object $value,
$classHint = null )
static

Set the value of a rich attribute, overwriting any previous value.

Generally mutating the result returned by the ::getAttribute*Default() methods should be done instead of using this method, since the objects returned are live.

Note
For attribute names where ::isHtmlAttributeWithSpecialSemantics() returns true you can customize the "flattened" representation used for HTML semantics via $codec->flatten() which falls back to $className::flatten().
Parameters
Element$nodeThe node on which the attribute is to be found.
string$nameThe name of the attribute.
object$valueThe new (object) value for the attribute
class-string | Hint | null$classHintOptional serialization hint

◆ setDataAttrI18n()

static Wikimedia\Parsoid\Utils\DOMDataUtils::setDataAttrI18n ( Element $node,
string $name,
I18nInfo $info )
static

Sets internationalization (i18n) information of a attribute value, used for later localization.

Parameters
Element$node
string$name
I18nInfo$info
Returns
void

◆ setDataMw()

static Wikimedia\Parsoid\Utils\DOMDataUtils::setDataMw ( Element $node,
?DataMw $dmw )
static

Set data meta wiki info from a node.

Parameters
Element$nodenode
?DataMw$dmwdata-mw

◆ setDataNodeI18n()

static Wikimedia\Parsoid\Utils\DOMDataUtils::setDataNodeI18n ( Element $node,
I18nInfo $info )
static

Sets internationalization (i18n) information of a node, used for later localization.

Parameters
Element$node
I18nInfo$info
Returns
void

◆ setDataParsoid()

static Wikimedia\Parsoid\Utils\DOMDataUtils::setDataParsoid ( Element $node,
DataParsoid $dp )
static

Set data parsoid info on a node.

Parameters
Element$nodenode
DataParsoid$dpdata-parsoid

◆ setDataParsoidDiff()

static Wikimedia\Parsoid\Utils\DOMDataUtils::setDataParsoidDiff ( Element $node,
?DataParsoidDiff $diffObj )
static

Set data diff info on a node.

Parameters
Element$nodenode
?DataParsoidDiff$diffObjdata-parsoid-diff object

◆ setJSONAttribute()

static Wikimedia\Parsoid\Utils\DOMDataUtils::setJSONAttribute ( Element $node,
string $name,
$obj )
static

Set a attribute on a node with a JSON-encoded object.

Parameters
Element$nodenode
string$nameName of the attribute.
mixed$objvalue of the attribute to
Deprecated
since 0.23; use setAttributeObject()

◆ setNodeData()

static Wikimedia\Parsoid\Utils\DOMDataUtils::setNodeData ( Element $node,
NodeData $data )
static

Set node data.

Parameters
Element$nodenode
NodeData$datadata

◆ setShadowInfo()

static Wikimedia\Parsoid\Utils\DOMDataUtils::setShadowInfo ( Element $node,
string $name,
$val )
static

Set shadow info on a node; similar to the method on tokens.

Records a key = value pair in data-parsoid['a'] property.

This is effectively a call of 'setShadowInfoIfModified' except there is no original value, so by definition, $val is modified.

Parameters
Element$nodenode
string$nameName of the attribute.
mixed$valval

◆ setShadowInfoIfModified()

static Wikimedia\Parsoid\Utils\DOMDataUtils::setShadowInfoIfModified ( Element $node,
string $name,
$val,
$origVal,
bool $skipOrig = false )
static

Set shadow info on a node; similar to the method on tokens.

If the new value ($val) for the key ($name) is different from the original value ($origVal):

  • the new value is recorded in data-parsoid->a and
  • the original value is recorded in data-parsoid->sa
Parameters
Element$nodenode
string$nameName of the attribute.
mixed$valval
mixed$origValoriginal value (null is a valid value)
bool$skipOrig

◆ stashObjectInDoc()

static Wikimedia\Parsoid\Utils\DOMDataUtils::stashObjectInDoc ( Document $doc,
NodeData $obj )
static

Stash $obj in $doc and return an id for later retrieval.

Parameters
Document$doc
NodeData$obj
Returns
int

◆ usedIdIndex()

static Wikimedia\Parsoid\Utils\DOMDataUtils::usedIdIndex ( SiteConfig $siteConfig,
Document $doc,
array $fragments = [] )
static

Builds an index of id attributes seen in the DOM.

Parameters
SiteConfig$siteConfigA SiteConfig is required to properly traverse document fragments embedded in extension DOM.
Document$doc
array<string,DocumentFragment>$fragments
Returns
array<string, true>

◆ visitAndLoadDataAttribs()

static Wikimedia\Parsoid\Utils\DOMDataUtils::visitAndLoadDataAttribs ( Node $node)
static

Walk DOM from $node downward calling loadDataAttribs.

This forces full eager loading of this subtree.

◆ visitAndStoreDataAttribs()

static Wikimedia\Parsoid\Utils\DOMDataUtils::visitAndStoreDataAttribs ( Node $node,
array $options = [] )
static

Walk DOM from node downward calling storeDataAttribs.

Parameters
Node$nodenode
array$optionsoptions

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