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 (Document $doc) |
Return the JsonCodec used for rich attributes in a Document. | |
static | isPrepared (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 | 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 $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 | validDataMw (Element $node) |
Check if there is meta wiki info in 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 | 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. | |
static | cloneDocumentFragment (DocumentFragment $df) |
Clones a DocumentFragment 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 | removeAttributeObject (Element $node, string $name) |
Remove a rich attribute. | |
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 |
Clones a node and its data bag.
Element | $elt | |
bool | $deep |
|
static |
Document | $doc | doc |
|
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.
@phan-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 and the class hint is a RichCodecable, a default value will be created using $className::defaultValue()
and stored as the value of the attribute.
@phan-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.
Document | $doc |
|
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 |
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 |
|
static |
Document | $doc | doc |
PageBundle | $pb | object |
|
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 |
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 by having the value implement RichCodecable::flatten()
.@phan-template T
Element | $node | The node on which the attribute is to be found. |
string | $name | The name of the attribute. @phan-suppress-next-line PhanTypeMismatchDeclaredParam |
T | $value | The new (object) value for the attribute |
class-string<T>|Hint<T>|null | $classHint Optional serialization hint @phpcs:ignore MediaWiki.Commenting.FunctionAnnotations.UnrecognizedAnnotation @phan-suppress-next-next-line PhanTemplateTypeNotUsedInFunctionReturn |
|
static |
Sets internationalization (i18n) information of a attribute value, used for later localization.
Element | $node | |
string | $name | |
I18nInfo | $info |
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 |
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.
Node | $node |
|
static |
Check if there is meta wiki info in a node.
Element | $node | node |
|
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 |