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 prepareDoc (Document $doc)
 
static prepareChildDoc (Document $topLevelDoc, Document $childDoc)
 
static stashObjectInDoc (Document $doc, NodeData $obj)
 Stash $obj in $doc and return an id for later retrieval.
 
static noAttrs (Element $node)
 Does this node have any attributes?
 
static getNodeData (Element $node)
 Get data object from a node.
 
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 getDataNodeI18n (Element $node)
 Retrieves internationalization (i18n) information of a node (typically for localization)
 
static setDataNodeI18n (Element $node, I18nInfo $i18n)
 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 $i18n)
 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 setDataParsoidDiff (Element $node, ?stdClass $diffObj)
 Set data diff info on a node.
 
static getDataMw (Element $node)
 Get data meta wiki info from a node.
 
static setDataMw (Element $node, ?DataMw $dmw)
 Set data meta wiki info from a node.
 
static validDataMw (Element $node)
 Check if there is meta wiki info in a node.
 
static validDataMwI18n (Element $node)
 Check if there is i18n info on a node (for the node or its attributes)
 
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 getPageBundle (Document $doc)
 Get this document's pagebundle object.
 
static storeInPageBundle (Element $node, Env $env, stdClass $data, array $idIndex)
 Removes the data-* attribute from a node, and migrates the data to the document's JSON store.
 
static injectPageBundle (Document $doc, PageBundle $pb)
 
static extractPageBundle (Document $doc)
 
static visitAndLoadDataAttribs (Node $node, array $options=[])
 Walk DOM from node downward calling loadDataAttribs.
 
static loadDataAttribs (Node $node, array $options)
 These are intended be used on a document after post-processing, so that the underlying .dataobject is transparently applied (in the store case) and reloaded (in the load case), rather than worrying about keeping the attributes up-to-date throughout that phase.
 
static usedIdIndex (Node $node)
 Builds an index of id attributes seen in the DOM.
 
static visitAndStoreDataAttribs (Node $node, array $options=[])
 Walk DOM from node downward calling storeDataAttribs.
 
static storeDataAttribs (Node $node, ?array $options=null)
 Copy data attributes from the bag to either JSON-encoded attributes on each node, or the page bundle, erasing the data-object-id attributes.
 
static cloneNode (Element $elt, bool $deep)
 Clones a node and its data bag.
 

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

◆ cloneNode()

static Wikimedia\Parsoid\Utils\DOMDataUtils::cloneNode ( Element $elt,
bool $deep )
static

Clones a node and its data bag.

Parameters
Element$elt
bool$deep
Returns
Element

◆ extractPageBundle()

static Wikimedia\Parsoid\Utils\DOMDataUtils::extractPageBundle ( Document $doc)
static
Parameters
Document$docdoc
Returns
stdClass|null

◆ getBag()

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

Return the dynamic "bag" property of a Document.

Parameters
Document$doc
Returns
DataBag

◆ 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

◆ 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
?stdClass

◆ 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

◆ getNodeData()

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

Get data object from a node.

Parameters
Element$nodenode
Returns
NodeData

◆ getPageBundle()

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

Get this document's pagebundle object.

Parameters
Document$doc
Returns
PageBundle

◆ injectPageBundle()

static Wikimedia\Parsoid\Utils\DOMDataUtils::injectPageBundle ( Document $doc,
PageBundle $pb )
static
Parameters
Document$docdoc
PageBundle$pbobject

◆ loadDataAttribs()

static Wikimedia\Parsoid\Utils\DOMDataUtils::loadDataAttribs ( Node $node,
array $options )
static

These are intended be used on a document after post-processing, so that the underlying .dataobject is transparently applied (in the store case) and reloaded (in the load case), rather than worrying about keeping the attributes up-to-date throughout that phase.

For the most part, using this.ppTo* should be sufficient and using these directly should be avoided.

Parameters
Node$nodenode
array$optionsoptions

◆ noAttrs()

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

Does this node have any attributes?

Parameters
Element$node
Returns
bool

◆ prepareChildDoc()

static Wikimedia\Parsoid\Utils\DOMDataUtils::prepareChildDoc ( Document $topLevelDoc,
Document $childDoc )
static
Parameters
Document$topLevelDoc
Document$childDoc

◆ setDataAttrI18n()

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

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

Parameters
Element$node
string$name
I18nInfo$i18n

◆ 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

◆ 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,
?stdClass $diffObj )
static

Set data diff info on a node.

Parameters
Element$nodenode
?stdClass$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

◆ 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

◆ storeDataAttribs()

static Wikimedia\Parsoid\Utils\DOMDataUtils::storeDataAttribs ( Node $node,
?array $options = null )
static

Copy data attributes from the bag to either JSON-encoded attributes on each node, or the page bundle, erasing the data-object-id attributes.

Parameters
Node$nodenode
?array$optionsoptions
  • discardDataParsoid: Discard DataParsoid objects instead of storing them
  • keepTmp: Preserve DataParsoid::$tmp
  • storeInPageBundle: If true, data will be stored in the page bundle instead of data-parsoid and data-mw.
  • env: The Env object required for various features
  • idIndex: Array of used ID attributes

◆ storeInPageBundle()

static Wikimedia\Parsoid\Utils\DOMDataUtils::storeInPageBundle ( Element $node,
Env $env,
stdClass $data,
array $idIndex )
static

Removes the data-* attribute from a node, and migrates the data to the document's JSON store.

Generates a unique id with the following format:

mw<base64-encoded counter>

but attempts to keep user defined ids.

TODO: Note that $data is effective a partial PageBundle containing only the 'parsoid' and 'mw' properties.

Parameters
Element$nodenode
Env$envenvironment
stdClass$datadata
array$idIndexIndex of used id attributes in the DOM

◆ usedIdIndex()

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

Builds an index of id attributes seen in the DOM.

Parameters
Node$node
Returns
array

◆ validDataMw()

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

Check if there is meta wiki info in a node.

Parameters
Element$nodenode
Returns
bool

◆ validDataMwI18n()

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

Check if there is i18n info on a node (for the node or its attributes)

Parameters
Element$node
Returns
bool

◆ visitAndLoadDataAttribs()

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

Walk DOM from node downward calling loadDataAttribs.

Parameters
Node$nodenode
array$optionsoptions

◆ 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: