MediaWiki master
ContentDOMTransformStage.php
Go to the documentation of this file.
1<?php
2declare( strict_types = 1 );
3
5
9use Wikimedia\Parsoid\DOM\Document;
10use Wikimedia\Parsoid\DOM\DocumentFragment;
11use Wikimedia\Parsoid\DOM\Element;
12use Wikimedia\Parsoid\DOM\Node;
13use Wikimedia\Parsoid\Utils\DOMCompat;
14
24
28 public function transform(
29 ParserOutput $po, ParserOptions $popts, array &$options
30 ): ParserOutput {
31 $contentHolder = $po->getContentHolder();
32 $df = $contentHolder->getAsDom( ContentHolder::BODY_FRAGMENT ) ??
33 $contentHolder->createFragment();
34
35 $df = $this->transformDOM( $df, $po, $popts, $options );
36
37 $contentHolder->setAsDom( ContentHolder::BODY_FRAGMENT, $df );
38 return $po;
39 }
40
42 abstract public function transformDOM(
43 DocumentFragment $df, ParserOutput $po, ParserOptions $popts, array &$options
44 ): DocumentFragment;
45
60 public function createElement(
61 Document $doc, string $name, array $attribs = [], Node|string ...$children
62 ): Element {
63 $el = $doc->createElement( $name );
64 foreach ( $attribs as $key => $value ) {
65 $el->setAttribute( $key, $value );
66 }
67 DOMCompat::append( $el, ...$children );
68 return $el;
69 }
70}
OutputTransformStages that modify the content as a HTML DOM tree.
createElement(Document $doc, string $name, array $attribs=[], Node|string ... $children)
Helper method for DOM transforms to easily create DOM Elements with the given attributes and children...
transform(ParserOutput $po, ParserOptions $popts, array &$options)
Transforms the input ParserOutput into the returned ParserOutput.The returned ParserOutput can explic...
transformDOM(DocumentFragment $df, ParserOutput $po, ParserOptions $popts, array &$options)
Applies the transformation to a DOM document.
Classes implementing the OutputTransformStage aim at being added to a pipeline of transformations tha...
Set options of the Parser.
ParserOutput is a rendering of a Content object or a message.