9use Wikimedia\Parsoid\Core\PageBundle;
10use Wikimedia\Parsoid\DOM\Document;
11use Wikimedia\Parsoid\Mocks\MockEnv;
12use Wikimedia\Parsoid\Utils\ContentUtils;
13use Wikimedia\Parsoid\Utils\DOMCompat;
14use Wikimedia\Parsoid\Utils\DOMDataUtils;
15use Wikimedia\Parsoid\Utils\DOMUtils;
34 if ( $hasPageBundle ) {
37 PageBundle::apply( $doc, $pb );
38 DOMDataUtils::prepareDoc( $doc );
39 DOMDataUtils::visitAndLoadDataAttribs(
40 DOMCompat::getBody( $doc )
43 $doc = ContentUtils::createAndLoadDocument(
48 $doc = $this->
transformDOM( $doc, $po, $popts, $options );
51 if ( $hasPageBundle ) {
52 DOMDataUtils::visitAndStoreDataAttribs(
53 DOMCompat::getBody( $doc ),
55 'storeInPageBundle' =>
true,
56 'env' =>
new MockEnv( [] ),
59 $pb = DOMDataUtils::getPageBundle( $doc );
60 $pb = self::workaroundT365036( $doc, $pb );
63 $text = ContentUtils::toXML( DOMCompat::getBody( $doc ), [
67 $text = ContentUtils::ppToXML( DOMCompat::getBody( $doc ), [
81 private function workaroundT365036( Document $doc, PageBundle $pb ): stdClass {
82 DOMDataUtils::injectPageBundle( $doc, $pb );
83 $convertedPageBundle = DOMDataUtils::extractPageBundle( $doc );
85 '@phan-var stdClass $convertedPageBundle';
86 return $convertedPageBundle;
OutputTransformStages that modify the content as a HTML DOM tree.
transformDOM(Document $dom, ParserOutput $po, ?ParserOptions $popts, array &$options)
Applies the transformation to a DOM document.
transform(ParserOutput $po, ?ParserOptions $popts, array &$options)
Transforms the input ParserOutput into the returned ParserOutput.The returned ParserOutput can explic...
Provides methods for conversion between PageBundle and ParserOutput TODO: Convert to a trait once we ...
static hasPageBundle(ParserOutput $parserOutput)
static pageBundleFromParserOutput(ParserOutput $parserOutput)
Returns a Parsoid PageBundle equivalent to the given ParserOutput.
static applyPageBundleDataToParserOutput( $pageBundle, ParserOutput $parserOutput)
Given an existing ParserOutput and a PageBundle, applies the PageBundle data to the ParserOutput.
Set options of the Parser.