Parsoid
A bidirectional parser between wikitext and HTML5
Parsoid\Utils\DOMDataUtils Class Reference

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

Static Public Member Functions

static noAttrs (DOMElement $node)
 Does this node have any attributes? More...
 
static getNodeData (DOMElement $node)
 Get data object from a node. More...
 
static setNodeData (DOMElement $node, stdClass $data)
 Set node data. More...
 
static getDataParsoid (DOMElement $node)
 Get data parsoid info from a node. More...
 
static setDataParsoid (DOMElement $node, stdClass $dp)
 Set data parsoid info on a node. More...
 
static getDataParsoidDiff (DOMElement $node)
 Get data diff info from a node. More...
 
static setDataParsoidDiff (DOMElement $node, ?stdClass $diffObj)
 Set data diff info on a node. More...
 
static getDataMw (DOMElement $node)
 Get data meta wiki info from a node. More...
 
static setDataMw (DOMElement $node, ?stdClass $dmw)
 Set data meta wiki info from a node. More...
 
static validDataMw (DOMElement $node)
 Check if there is meta wiki info in a node. More...
 
static getJSONAttribute (DOMElement $node, string $name, $defaultVal)
 Get an object from a JSON-encoded XML attribute on a node. More...
 
static setJSONAttribute (DOMElement $node, string $name, $obj)
 Set a attribute on a node with a JSON-encoded object. More...
 
static setShadowInfo (DOMElement $node, string $name, $val)
 Set shadow info on a node; similar to the method on tokens. More...
 
static setShadowInfoIfModified (DOMElement $node, string $name, $val, $origVal, bool $skipOrig=false)
 Set shadow info on a node; similar to the method on tokens. More...
 
static addAttributes (DOMElement $elt, array $attrs)
 Add attributes to a node element. More...
 
static addNormalizedAttribute (DOMElement $node, string $name, $val, $origVal, bool $skipOrig=false)
 Set an attribute and shadow info to a node. More...
 
static hasTypeOf (DOMNode $node, string $type)
 Test if a node matches a given typeof. More...
 
static addTypeOf (DOMElement $node, string $type)
 Add a type to the typeof attribute. More...
 
static removeTypeOf (DOMElement $node, string $type)
 Remove a type from the typeof attribute. More...
 
static getPageBundle (DOMDocument $doc)
 Get this document's pagebundle object. More...
 
static storeInPageBundle (DOMElement $node, Env $env, stdClass $data, array $idIndex)
 Removes the data-* attribute from a node, and migrates the data to the document's JSON store. More...
 
static injectPageBundle (DOMDocument $doc, stdClass $obj)
 
static extractPageBundle (DOMDocument $doc)
 
static applyPageBundle (DOMDocument $doc, PageBundle $pb)
 Applies the data-* attributes JSON structure to the document. More...
 
static visitAndLoadDataAttribs (DOMNode $node, array $options=[])
 Walk DOM from node downward calling loadDataAttribs. More...
 
static massageLoadedDataParsoid (stdClass $dp, array $options=[], DOMElement $node=null)
 Massage the data parsoid object loaded from a node attribute into expected shape. More...
 
static loadDataAttribs (DOMNode $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. More...
 
static usedIdIndex (DOMNode $node)
 Builds an index of id attributes seen in the DOM. More...
 
static visitAndStoreDataAttribs (DOMNode $node, array $options=[])
 Walk DOM from node downward calling storeDataAttribs. More...
 
static storeDataAttribs (DOMNode $node, ?array $options=null)
 PORT_FIXME This function needs an accurate description. More...
 

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

◆ addAttributes()

static Parsoid\Utils\DOMDataUtils::addAttributes ( DOMElement  $elt,
array  $attrs 
)
static

Add attributes to a node element.

Parameters
DOMElement$eltelement
array$attrsattributes

◆ addNormalizedAttribute()

static Parsoid\Utils\DOMDataUtils::addNormalizedAttribute ( DOMElement  $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
DOMElement$nodenode
string$nameName of the attribute.
mixed$valvalue
mixed$origValoriginal value
bool$skipOrig

◆ addTypeOf()

static Parsoid\Utils\DOMDataUtils::addTypeOf ( DOMElement  $node,
string  $type 
)
static

Add a type to the typeof attribute.

This method works for both tokens and DOM nodes as it only relies on getAttribute and setAttribute, which are defined for both.

Parameters
DOMElement$nodenode
string$typetype

◆ applyPageBundle()

static Parsoid\Utils\DOMDataUtils::applyPageBundle ( DOMDocument  $doc,
PageBundle  $pb 
)
static

Applies the data-* attributes JSON structure to the document.

Leaves id attributes behind – they are used by citation code to extract <ref> body from the DOM.

Parameters
DOMDocument$docdoc
PageBundle$pbpage bundle

◆ extractPageBundle()

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

◆ getDataMw()

static Parsoid\Utils\DOMDataUtils::getDataMw ( DOMElement  $node)
static

Get data meta wiki info from a node.

Parameters
DOMElement$nodenode
Returns
stdClass

◆ getDataParsoid()

static Parsoid\Utils\DOMDataUtils::getDataParsoid ( DOMElement  $node)
static

Get data parsoid info from a node.

Parameters
DOMElement$nodenode
Returns
DataParsoid

◆ getDataParsoidDiff()

static Parsoid\Utils\DOMDataUtils::getDataParsoidDiff ( DOMElement  $node)
static

Get data diff info from a node.

Parameters
DOMElement$nodenode
Returns
?stdClass

◆ getJSONAttribute()

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

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

Parameters
DOMElement$nodenode
string$namename
mixed$defaultVal
Returns
mixed

◆ getNodeData()

static Parsoid\Utils\DOMDataUtils::getNodeData ( DOMElement  $node)
static

Get data object from a node.

Parameters
DOMElement$nodenode
Returns
stdClass

◆ getPageBundle()

static Parsoid\Utils\DOMDataUtils::getPageBundle ( DOMDocument  $doc)
static

Get this document's pagebundle object.

Parameters
DOMDocument$doc
Returns
stdClass

◆ hasTypeOf()

static Parsoid\Utils\DOMDataUtils::hasTypeOf ( DOMNode  $node,
string  $type 
)
static

Test if a node matches a given typeof.

Parameters
DOMNode$nodenode
string$typetype
Returns
bool

◆ injectPageBundle()

static Parsoid\Utils\DOMDataUtils::injectPageBundle ( DOMDocument  $doc,
stdClass  $obj 
)
static
Parameters
DOMDocument$docdoc
stdClass$objobject

◆ loadDataAttribs()

static Parsoid\Utils\DOMDataUtils::loadDataAttribs ( DOMNode  $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
DOMNode$nodenode
array$optionsoptions

◆ massageLoadedDataParsoid()

static Parsoid\Utils\DOMDataUtils::massageLoadedDataParsoid ( stdClass  $dp,
array  $options = [],
DOMElement  $node = null 
)
static

Massage the data parsoid object loaded from a node attribute into expected shape.

When we create a first-class object for data-parsoid, this will move into the constructor.

Parameters
stdClass$dp
array$options
DOMElement | null$node

◆ noAttrs()

static Parsoid\Utils\DOMDataUtils::noAttrs ( DOMElement  $node)
static

Does this node have any attributes?

Parameters
DOMElement$node
Returns
bool

◆ removeTypeOf()

static Parsoid\Utils\DOMDataUtils::removeTypeOf ( DOMElement  $node,
string  $type 
)
static

Remove a type from the typeof attribute.

This method works on both tokens and DOM nodes as it only relies on getAttribute/setAttribute/removeAttribute.

Parameters
DOMElement$nodenode
string$typetype

◆ setDataMw()

static Parsoid\Utils\DOMDataUtils::setDataMw ( DOMElement  $node,
?stdClass  $dmw 
)
static

Set data meta wiki info from a node.

Parameters
DOMElement$nodenode
?stdClass$dmw data-mw

◆ setDataParsoid()

static Parsoid\Utils\DOMDataUtils::setDataParsoid ( DOMElement  $node,
stdClass  $dp 
)
static

Set data parsoid info on a node.

Parameters
DOMElement$nodenode
stdClass$dpdata-parsoid

◆ setDataParsoidDiff()

static Parsoid\Utils\DOMDataUtils::setDataParsoidDiff ( DOMElement  $node,
?stdClass  $diffObj 
)
static

Set data diff info on a node.

Parameters
DOMElement$nodenode
?stdClass$diffObj data-parsoid-diff object

◆ setJSONAttribute()

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

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

Parameters
DOMElement$nodenode
string$nameName of the attribute.
mixed$objvalue of the attribute to

◆ setNodeData()

static Parsoid\Utils\DOMDataUtils::setNodeData ( DOMElement  $node,
stdClass  $data 
)
static

Set node data.

Parameters
DOMElement$nodenode
stdClass$datadata

◆ setShadowInfo()

static Parsoid\Utils\DOMDataUtils::setShadowInfo ( DOMElement  $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
DOMElement$nodenode
string$nameName of the attribute.
mixed$valval

◆ setShadowInfoIfModified()

static Parsoid\Utils\DOMDataUtils::setShadowInfoIfModified ( DOMElement  $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
DOMElement$nodenode
string$nameName of the attribute.
mixed$valval
mixed$origValoriginal value (null is a valid value)
bool$skipOrig

◆ storeDataAttribs()

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

PORT_FIXME This function needs an accurate description.

Parameters
DOMNode$nodenode
?array|null$options options

◆ storeInPageBundle()

static Parsoid\Utils\DOMDataUtils::storeInPageBundle ( DOMElement  $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.

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

◆ usedIdIndex()

static Parsoid\Utils\DOMDataUtils::usedIdIndex ( DOMNode  $node)
static

Builds an index of id attributes seen in the DOM.

Parameters
DOMNode$node
Returns
array

◆ validDataMw()

static Parsoid\Utils\DOMDataUtils::validDataMw ( DOMElement  $node)
static

Check if there is meta wiki info in a node.

Parameters
DOMElement$nodenode
Returns
bool

◆ visitAndLoadDataAttribs()

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

Walk DOM from node downward calling loadDataAttribs.

Parameters
DOMNode$nodenode
array$optionsoptions

◆ visitAndStoreDataAttribs()

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

Walk DOM from node downward calling storeDataAttribs.

Parameters
DOMNode$nodenode
array$optionsoptions

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