Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 8 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
ParserHookProcessor | |
0.00% |
0 / 8 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
staticTagPostProcessor | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
20 | |||
wtPostprocess | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | declare( strict_types = 1 ); |
3 | |
4 | namespace Wikimedia\Parsoid\ParserTests; |
5 | |
6 | use stdClass; |
7 | use Wikimedia\Parsoid\DOM\Element; |
8 | use Wikimedia\Parsoid\DOM\Node; |
9 | use Wikimedia\Parsoid\Ext\DOMDataUtils; |
10 | use Wikimedia\Parsoid\Ext\DOMProcessor as ExtDOMProcessor; |
11 | use Wikimedia\Parsoid\Ext\ParsoidExtensionAPI; |
12 | use Wikimedia\Parsoid\Utils\DOMUtils; |
13 | |
14 | /** |
15 | * See tests/parser/ParserTestParserHook.php in core. |
16 | */ |
17 | class ParserHookProcessor extends ExtDOMProcessor { |
18 | |
19 | public function staticTagPostProcessor( |
20 | Node $node, stdClass $obj |
21 | ): void { |
22 | if ( $node instanceof Element ) { |
23 | if ( DOMUtils::hasTypeOf( $node, 'mw:Extension/statictag' ) ) { |
24 | $dataMw = DOMDataUtils::getDataMw( $node ); |
25 | if ( ( $dataMw->attrs->action ?? null ) === 'flush' ) { |
26 | $node->appendChild( $node->ownerDocument->createTextNode( $obj->buf ) ); |
27 | $obj->buf = ''; |
28 | } else { |
29 | $obj->buf .= $dataMw->body->extsrc; |
30 | } |
31 | } |
32 | } |
33 | } |
34 | |
35 | /** |
36 | * @inheritDoc |
37 | */ |
38 | public function wtPostprocess( |
39 | ParsoidExtensionAPI $extApi, Node $node, array $options |
40 | ): void { |
41 | // Pass an object since we want the data to be carried around across |
42 | // nodes in the DOM. Passing an array won't work since visitDOM doesn't |
43 | // use a reference on its end. Maybe we could fix that separately. |
44 | DOMUtils::visitDOM( $node, [ $this, 'staticTagPostProcessor' ], (object)[ 'buf' => '' ] ); |
45 | } |
46 | } |