|
Parsoid
A bidirectional parser between wikitext and HTML5
|
Helper class that provides missing DOM level 3 methods for the PHP DOM classes. More...
Static Public Member Functions | |
| static | isStandardsMode ( $node=null) |
| static | isUsingDodo ( $node=null) |
| static | isUsing84Dom ( $node=null) |
| static | newDocument (bool $isHtml=true) |
| Create a new empty HTML document using the preferred DOM implementation. | |
| static | getTitle ( $document) |
| Get document title. | |
| static | setTitle ( $document, string $title) |
| Set document title. | |
| static | getElementById (DOMDocument|DOMDocumentFragment|Document|DocumentFragment $node, string $id) |
| Return the descendant with the specified ID. | |
| static | setIdAttribute ( $element, string $id) |
Workaround bug in PHP's Document::getElementById() which doesn't actually index the 'id' attribute unless you use the non-standard Element::setIdAttribute method after the attribute is set; see https://www.php.net/manual/en/domdocument.getelementbyid.php for more details. | |
| static | getElementsByTagName (DOMDocument|DOMElement|Document|Element $node, string $tagName) |
| Return all descendants with the specified tag name. | |
| static | getFirstElementChild (DOMDocument|DOMDocumentFragment|DOMElement|Document|DocumentFragment|Element $node) |
| Return the first child of the node that is an Element, or null otherwise. | |
| static | getLastElementChild (DOMDocument|DOMDocumentFragment|DOMElement|Document|DocumentFragment|Element $node) |
| Return the last child of the node that is an Element, or null otherwise. | |
| static | querySelector ( $node, string $selector) |
| static | querySelectorAll (DOMDocument|DOMDocumentFragment|DOMElement|Document|DocumentFragment|Element $node, string $selector) |
| static | getPreviousElementSibling (DOMElement|DOMCharacterData|Element|CharacterData $node) |
| Return the last preceding sibling of the node that is an element, or null otherwise. | |
| static | getNextElementSibling (DOMElement|DOMCharacterData|Element|CharacterData $node) |
| Return the first following sibling of the node that is an element, or null otherwise. | |
| static | append (DOMDocument|DOMDocumentFragment|DOMElement|Document|DocumentFragment|Element $parentNode, DOMNode|Node|string ... $nodes) |
| Append the node to the parent node. | |
| static | appendChild (DOMDocument|DOMDocumentFragment|DOMElement|Document|DocumentFragment|Element $parentNode, DOMNode|Node $node) |
| Append a child node to the parent node. | |
| static | remove (DOMElement|DOMCharacterData|Element|CharacterData $node) |
| Removes the node from the document. | |
| static | getInnerHTML ( $element) |
| Get innerHTML. | |
| static | setInnerHTML ( $element, string $html) |
| Set innerHTML. | |
| static | getOuterHTML ( $element) |
| Get outerHTML. | |
| static | getAttribute ( $element, string $attributeName) |
| Return the value of an element attribute. | |
| static | attributes (Element $element) |
| Get an associative array of attributes, suitable for serialization. | |
| static | getClassList ( $node) |
| Return the class list of this element. | |
| static | normalize ( $elt) |
| static | replaceChildren (DOMDocument|DOMDocumentFragment|DOMElement|Document|DocumentFragment|Element $parentNode, DOMNode|Node|string ... $nodes) |
| ParentNode.replaceChildren() https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/replaceChildren. | |
| static | getTemplateElementContent ( $node) |
| Return HTMLTemplateElement::content. | |
Helper class that provides missing DOM level 3 methods for the PHP DOM classes.
For a DOM method $node->foo( $bar) the equivalent helper is DOMCompat::foo( $node, $bar ). For a DOM property $node->foo there is a DOMCompat::getFoo( $node ) and DOMCompat::setFoo( $node, $value ).
Only implements the methods that are actually used by Parsoid.
Because this class may be used by code outside Parsoid, it tries to be relatively tolerant of object types: you can call it either with PHP's DOM* types or with a "proper" DOM implementation, and it will attempt to Do The Right Thing regardless. As a result, there are generally not parameter type hints for DOM object types, and the return types will be broad enough to accomodate the value a "real" DOM implementation would return, as well as the values our thunk will return. (For instance, we can't create a "real" NodeList in our compatibility thunk.)
Exception to the above: ::nodeName method is not so much a DOM compatibility method in the sense above, but a proxy to let us support multiple DOM libraries against the Parsoid codebase that expects lower-case names. In this specific instance the default behavior is tailored for performance vs. being HTML-standards-compliant.
|
static |
Append the node to the parent node.
| Document | DocumentFragment | Element | $parentNode | |
| Node|string | ...$nodes |
|
static |
Append a child node to the parent node.
| Document | DocumentFragment | Element | $parentNode | |
| Node | $node |
|
static |
Get an associative array of attributes, suitable for serialization.
Add the xmlns attribute if available, to workaround PHP's surprising behavior with the xmlns attribute: HTML is not an XML document, but various parts of PHP pretend that it is, sort of.
| Element | $element |
attributes property.
|
static |
Return the value of an element attribute.
Unlike PHP's version, this is spec-compliant and returns null if the attribute is not present, allowing the caller to distinguish between "the attribute exists but has the empty string as its value" and "the attribute does not exist".
| Element | $element | |
| string | $attributeName |
null if the attribute does not exist on the element.
|
static |
Return the class list of this element.
| Element | $node |
|
static |
Return the descendant with the specified ID.
Workaround for https://bugs.php.net/bug.php?id=77686 and other issues related to inconsistent indexing behavior. XXX: 77686 is fixed in php 8.1.21
| Document | DocumentFragment | $node | |
| string | $id |
|
static |
Return all descendants with the specified tag name.
Workaround for PHP's getElementsByTagName being inexplicably slow in some situations and the lack of Element::getElementsByTagName().
| Document | Element | $node | |
| string | $tagName |
|
static |
Return the first child of the node that is an Element, or null otherwise.
| Document | DocumentFragment | Element | $node |
|
static |
Get innerHTML.
| Element | $element |
|
static |
Return the last child of the node that is an Element, or null otherwise.
| Document | DocumentFragment | Element | $node |
|
static |
Return the first following sibling of the node that is an element, or null otherwise.
| Element | CharacterData | $node |
|
static |
Get outerHTML.
| Element | $element |
|
static |
Return the last preceding sibling of the node that is an element, or null otherwise.
| Element | CharacterData | $node |
|
static |
Return HTMLTemplateElement::content.
In the PHP DOM, <template> elements do not have a dedicated DocumentFragment and children are stored directly under the Element. In the HTML5 spec, the contents are stored in a DocumentFragment with a unique owner document.
Bridge this gap by returning the <template> element for PHP's DOM, or the DocumentFragment for an HTML5-compliant DOM.
| Element | $node | A <template> element |
|
static |
Get document title.
| Document | $document |
|
static |
| Node | null | $node | If present, we'll use the type of the given node to determine whether to use standards mode. |
|
static |
| Node | null | $node | If present, we'll use the type of the given node to determine whether we're using the PHP 8.4 DOM implementation. |
|
static |
| Node | null | $node | If present, we'll use the type of the given node to determine whether we're using Dodo. |
|
static |
Create a new empty HTML document using the preferred DOM implementation.
| bool | $isHtml | (optional) Should always be true. |
|
static |
| Element | DocumentFragment | $elt | root of the DOM tree that needs to be normalized |
|
static |
| Document | DocumentFragment | Element | $node | |
| string | $selector |
|
static |
| Document | DocumentFragment | Element | $node | |
| string | $selector |
|
static |
Removes the node from the document.
| Element | CharacterData | $node |
|
static |
ParentNode.replaceChildren() https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/replaceChildren.
| Document | DocumentFragment | Element | $parentNode | |
| Node|string | ...$nodes |
|
static |
Workaround bug in PHP's Document::getElementById() which doesn't actually index the 'id' attribute unless you use the non-standard Element::setIdAttribute method after the attribute is set; see https://www.php.net/manual/en/domdocument.getelementbyid.php for more details.
| Element | $element | |
| string | $id | The desired value for the id attribute on $element. |
|
static |
Set innerHTML.
| Element | $element | |
| string | $html |
|
static |
Set document title.
| Document | $document | |
| string | $title |