Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 30 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
ProcessEmbeddedDocs | |
0.00% |
0 / 30 |
|
0.00% |
0 / 2 |
56 | |
0.00% |
0 / 1 |
processNode | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
12 | |||
run | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
20 |
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\PipelineUtils; |
12 | use Wikimedia\Parsoid\Wt2Html\Wt2HtmlDOMProcessor; |
13 | |
14 | /** |
15 | */ |
16 | class ProcessEmbeddedDocs implements Wt2HtmlDOMProcessor { |
17 | private Env $env; |
18 | private ParsoidExtensionAPI $extApi; |
19 | |
20 | private function processNode( Element $elt ): void { |
21 | $doc = $elt->ownerDocument; |
22 | ContentUtils::processAttributeEmbeddedHTML( |
23 | $this->extApi, |
24 | $elt, |
25 | function ( string $html ) use ( $doc ) { |
26 | $df = ContentUtils::createAndLoadDocumentFragment( $doc, $html ); |
27 | PipelineUtils::processContentInPipeline( |
28 | $this->env, |
29 | $this->env->topFrame, |
30 | $df, |
31 | [ |
32 | 'pipelineType' => 'fullparse-embedded-docs-dom-to-dom', |
33 | 'pipelineOpts' => [], |
34 | 'sol' => true |
35 | ], |
36 | ); |
37 | return ContentUtils::ppToXML( $df, [ 'innerXML' => true ] ); |
38 | } |
39 | ); |
40 | |
41 | $child = $elt->firstChild; |
42 | while ( $child ) { |
43 | if ( $child instanceof Element ) { |
44 | $this->processNode( $child ); |
45 | } |
46 | $child = $child->nextSibling; |
47 | } |
48 | } |
49 | |
50 | /** |
51 | * DOM Postprocessor entry function to walk DOM rooted at $root |
52 | * and convert the DSR offsets as needed. |
53 | * @see ConvertUtils::convertOffsets |
54 | * |
55 | * @inheritDoc |
56 | */ |
57 | public function run( |
58 | Env $env, Node $root, array $options = [], bool $atTopLevel = false |
59 | ): void { |
60 | $this->env = $env; |
61 | $this->extApi = new ParsoidExtensionAPI( $env ); |
62 | |
63 | $children = ( $root instanceof Element ) ? [ $root ] : $root->childNodes; |
64 | foreach ( $children as $child ) { |
65 | if ( $child instanceof Element ) { |
66 | $this->processNode( $child ); |
67 | } |
68 | } |
69 | } |
70 | } |