Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| WikifunctionsPFragment | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
| asDom | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * WikiLambda extension Parsoid fragment our parser function |
| 5 | * |
| 6 | * @file |
| 7 | * @ingroup Extensions |
| 8 | * @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt |
| 9 | * @license MIT |
| 10 | */ |
| 11 | |
| 12 | namespace MediaWiki\Extension\WikiLambda\ParserFunction; |
| 13 | |
| 14 | use Wikimedia\Parsoid\DOM\DocumentFragment; |
| 15 | use Wikimedia\Parsoid\Ext\ParsoidExtensionAPI; |
| 16 | use Wikimedia\Parsoid\Fragments\LiteralStringPFragment; |
| 17 | |
| 18 | class WikifunctionsPFragment extends LiteralStringPFragment { |
| 19 | // TODO: Alter this so we can control serialisation etc. |
| 20 | |
| 21 | /** |
| 22 | * @inheritDoc |
| 23 | */ |
| 24 | public function asDom( ParsoidExtensionAPI $ext, bool $release = false ): DocumentFragment { |
| 25 | if ( !$this->isEmpty() ) { |
| 26 | return parent::asDom( $ext, $release ); |
| 27 | } |
| 28 | |
| 29 | // (T391589) LiteralStringPFragment::asDom fails when the value is empty, |
| 30 | // adding excecption here to create an empty text node. |
| 31 | $doc = $ext->getTopLevelDoc(); |
| 32 | $df = $doc->createDocumentFragment(); |
| 33 | $df->appendChild( $doc->createTextNode( '' ) ); |
| 34 | |
| 35 | return $df; |
| 36 | } |
| 37 | } |