Debian Codegraph @

vendor/wikimedia/parsoid/src/Wt2Html/DOM/Processors/ProcessEmbeddedDocs.php

raw
1 <?php
2 declare( strict_types = 1 );
3
4 namespace Wikimedia\Parsoid\Wt2Html\DOM\Processors;
5
6 use Wikimedia\Parsoid\Config\Env;
7 use Wikimedia\Parsoid\DOM\Element;
8 use Wikimedia\Parsoid\DOM\Node;
9 use Wikimedia\Parsoid\Ext\ParsoidExtensionAPI;
10 use Wikimedia\Parsoid\Utils\ContentUtils;
11 use Wikimedia\Parsoid\Utils\DOMCompat;
12 use Wikimedia\Parsoid\Utils\DOMDataUtils;
13 use Wikimedia\Parsoid\Utils\PipelineUtils;
14 use Wikimedia\Parsoid\Wt2Html\Wt2HtmlDOMProcessor;
15
16 /**
17 */
18 class ProcessEmbeddedDocs implements Wt2HtmlDOMProcessor {
19 private Env $env;
20 private ParsoidExtensionAPI $extApi;
21
22 private function processNode( Element $elt ): void {
23 ContentUtils::processAttributeEmbeddedHTML(
24 $this->extApi,
25 $elt,
26 function ( string $html ) {
27 $dom = ContentUtils::createDocument( $html );
28 $body = DOMCompat::getBody( $dom );
29 DOMDataUtils::visitAndLoadDataAttribs( $body );
30 PipelineUtils::processContentInPipeline(
31 $this->env,
32 $this->env->topFrame,
33 $body,
34 [
35 'pipelineType' => 'fullparse-embedded-docs-dom-to-dom',
36 'pipelineOpts' => [],
37 'sol' => true
38 ],
39 );
40 return ContentUtils::ppToXML( $body, [ 'innerXML' => true ] );
41 }
42 );
43
44 $child = $elt->firstChild;
45 while ( $child ) {
46 if ( $child instanceof Element ) {
47 $this->processNode( $child );
48 }
49 $child = $child->nextSibling;
50 }
51 }
52
53 /**
54 * DOM Postprocessor entry function to walk DOM rooted at $root
55 * and convert the DSR offsets as needed.
56 * @see ConvertUtils::convertOffsets
57 *
58 * @inheritDoc
59 */
60 public function run(
61 Env $env, Node $root, array $options = [], bool $atTopLevel = false
62 ): void {
63 $this->env = $env;
64 $this->extApi = new ParsoidExtensionAPI( $env );
65 '@phan-var Element $root';
66 $this->processNode( $root );
67 }
68 }