|
Parsoid
A bidirectional parser between wikitext and HTML5
|
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 | isPrepared (Document $doc) |
| static | isPreparedAndLoaded (Document $doc) |
| 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 | dedupeNodeData (Node $clonedRoot) |
| static | noAttrs (Element $node) |
| Does this node have any attributes? | |
| static | getNodeData (Element $node, ?BasePageBundle $pb=null) |
| 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 | 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 | 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 | storeInPageBundle (DomPageBundle $pb, Element $node, stdClass $data, array $idIndex) |
Removes the data-* attribute from a node, and migrates the data to the given DomPageBundle. | |
| static | getCodecHints () |
| Helper function to create static Hint objects for JsonCodec. | |
| 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 (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 | 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 (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' |
These helpers pertain to HTML and data attributes of a node.
|
static |
Set an attribute and shadow info to a node.
Similar to the method on tokens
| Element | $node | node |
| string | $name | Name of the attribute. |
| mixed | $val | value |
| mixed | $origVal | original value |
| bool | $skipOrig |
|
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.
| Element | $node | |
| array | &$attrs | |
| bool | $keepTmp | |
| bool | $storeDiffMark |
|
static |
Return the value of a rich attribute as a live DocumentFragment.
This also serves as an assertion that there are not conflicting types.
| Element | $node | The node on which the attribute is to be found. |
| string | $name | The name of the attribute. |
|
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.
| Element | $node | The node on which the attribute is to be found. |
| string | $name | The name of the attribute. |
|
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
| Element | $node | The node on which the attribute is to be found. |
| string | $name | The name of the attribute. |
| class-string<T>|Hint<T> | $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.
@template T
| Element | $node | The node on which the attribute is to be found. |
| string | $name | The name of the attribute. |
| class-string<T>|Hint<T> | $classHint |
|
static |
Return the dynamic "bag" property of a Document.
| Document | $doc |
|
static |
Return the JsonCodec used for rich attributes in a Document.
| Node | $node |
|
static |
Helper function to create static Hint objects for JsonCodec.
|
static |
Retrieves internationalization (i18n) information of an attribute value (typically for localization)
| Element | $node | |
| string | $name |
|
static |
| Element | $node |
|
static |
Get data meta wiki info from a node.
| Element | $node | node |
|
static |
Returns the language variant information of a node.
| Element | $node |
|
static |
Retrieves internationalization (i18n) information of a node (typically for localization)
| Element | $node |
|
static |
Get data parsoid info from a node.
| Element | $node | node |
|
static |
Get data diff info from a node.
| Element | $node | node |
|
static |
Get data diff info from a node, setting a default value if not present.
| Element | $node | node |
|
static |
Get an object from a JSON-encoded XML attribute on a node.
| Element | $node | node |
| string | $name | name |
| mixed | $defaultVal |
|
static |
Get data object from a node.
| Element | $node | node |
| ?BasePageBundle | $pb | Optional source for node data |
|
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.
| Node | $node | node |
| array | $options | options |
|
static |
Does this node have any attributes?
| Element | $node |
|
static |
| Document | $topLevelDoc | |
| Document | $childDoc |
|
static |
Remove a rich attribute.
| Element | $node | The node on which the attribute is to be found. |
| string | $name | The name of the attribute. |
|
static |
Remove a rich attribute.
| Element | $node | The node on which the attribute is to be found. |
| string | $name | The name of the attribute. |
|
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.
| Element | $node | The node on which the attribute is to be found. |
| string | $name | The name of the attribute. |
| 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.
::isHtmlAttributeWithSpecialSemantics() returns true you can customize the "flattened" representation used for HTML semantics via $codec->flatten() which falls back to $className::flatten().| Element | $node | The node on which the attribute is to be found. |
| string | $name | The name of the attribute. |
| object | $value | The new (object) value for the attribute |
| class-string | Hint | null | $classHint | Optional serialization hint |
|
static |
Sets internationalization (i18n) information of a attribute value, used for later localization.
| Element | $node | |
| string | $name | |
| I18nInfo | $info |
|
static |
Set data meta wiki info from a node.
| Element | $node | node |
| ?DataMw | $dmw | data-mw |
|
static |
Sets internationalization (i18n) information of a node, used for later localization.
| Element | $node | |
| I18nInfo | $info |
|
static |
Set data parsoid info on a node.
| Element | $node | node |
| DataParsoid | $dp | data-parsoid |
|
static |
Set data diff info on a node.
| Element | $node | node |
| ?DataParsoidDiff | $diffObj | data-parsoid-diff object |
|
static |
Set a attribute on a node with a JSON-encoded object.
| Element | $node | node |
| string | $name | Name of the attribute. |
| mixed | $obj | value of the attribute to |
|
static |
Set node data.
| Element | $node | node |
| NodeData | $data | data |
|
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.
| Element | $node | node |
| string | $name | Name of the attribute. |
| mixed | $val | val |
|
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):
| Element | $node | node |
| string | $name | Name of the attribute. |
| mixed | $val | val |
| mixed | $origVal | original value (null is a valid value) |
| bool | $skipOrig |
|
static |
Stash $obj in $doc and return an id for later retrieval.
| Document | $doc | |
| NodeData | $obj |
|
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.
| Node | $node | node |
| ?array | $options | options
|
|
static |
Removes the data-* attribute from a node, and migrates the data to the given DomPageBundle.
Generates a unique id with the following format:
but attempts to keep user defined ids.
TODO: Note that $data is effective a partial PageBundle containing only the 'parsoid' and 'mw' properties.
| DomPageBundle | $pb | |
| Element | $node | node |
| stdClass | $data | data |
| array | $idIndex | Index of used id attributes in the DOM |
|
static |
Builds an index of id attributes seen in the DOM.
| SiteConfig | $siteConfig | A SiteConfig is required to properly traverse document fragments embedded in extension DOM. |
| Document | $doc | |
| array<string,DocumentFragment> | $fragments |
|
static |
Walk DOM from node downward calling loadDataAttribs.
| Node | $node | node |
| array | $options | options |
|
static |
Walk DOM from node downward calling storeDataAttribs.
| Node | $node | node |
| array | $options | options |