Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 22 |
ParserHookProcessor | |
0.00% |
0 / 1 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 22 |
staticTagPostProcessor | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 14 |
|||
wtPostprocess | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 8 |
<?php | |
declare( strict_types = 1 ); | |
namespace Wikimedia\Parsoid\ParserTests; | |
use stdClass; | |
use Wikimedia\Parsoid\DOM\Element; | |
use Wikimedia\Parsoid\DOM\Node; | |
use Wikimedia\Parsoid\Ext\DOMDataUtils; | |
use Wikimedia\Parsoid\Ext\DOMProcessor as ExtDOMProcessor; | |
use Wikimedia\Parsoid\Ext\ParsoidExtensionAPI; | |
use Wikimedia\Parsoid\Utils\DOMUtils; | |
use Wikimedia\Parsoid\Utils\PHPUtils; | |
/** | |
* See tests/parser/ParserTestParserHook.php in core. | |
*/ | |
class ParserHookProcessor extends ExtDOMProcessor { | |
/** | |
* @param Node $node | |
* @param stdClass $obj | |
*/ | |
public function staticTagPostProcessor( | |
Node $node, stdClass $obj | |
): void { | |
if ( $node instanceof Element ) { | |
if ( DOMUtils::hasTypeOf( $node, 'mw:Extension/statictag' ) ) { | |
$dataMw = DOMDataUtils::getDataMw( $node ); | |
if ( ( $dataMw->attrs->action ?? null ) === 'flush' ) { | |
$node->appendChild( $node->ownerDocument->createTextNode( $obj->buf ) ); | |
$obj->buf = ''; | |
} else { | |
$obj->buf .= $dataMw->body->extsrc; | |
} | |
} | |
} | |
} | |
/** | |
* @inheritDoc | |
*/ | |
public function wtPostprocess( | |
ParsoidExtensionAPI $extApi, Node $node, array $options, | |
bool $atTopLevel | |
): void { | |
if ( $atTopLevel ) { | |
// Pass an object since we want the data to be carried around across | |
// nodes in the DOM. Passing an array won't work since visitDOM doesn't | |
// use a reference on its end. Maybe we could fix that separately. | |
DOMUtils::visitDOM( $node, [ $this, 'staticTagPostProcessor' ], | |
PHPUtils::arrayToObject( [ 'buf' => '' ] ) ); | |
} | |
} | |
} |