Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ParsoidWikitextParser | |
0.00% |
0 / 10 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| parse | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Kartographer; |
| 4 | |
| 5 | use Wikimedia\Parsoid\Ext\ParsoidExtensionAPI; |
| 6 | |
| 7 | /** |
| 8 | * @license MIT |
| 9 | */ |
| 10 | class ParsoidWikitextParser extends WikitextParser { |
| 11 | |
| 12 | public function __construct( |
| 13 | private readonly ParsoidExtensionAPI $extApi, |
| 14 | ) { |
| 15 | } |
| 16 | |
| 17 | /** @inheritDoc */ |
| 18 | protected function parse( string $wikiText ): string { |
| 19 | $dom = $this->extApi->wikitextToDOM( $wikiText, [ |
| 20 | 'parseOpts' => [ |
| 21 | 'extTag' => $this->extApi->extTag->getName(), |
| 22 | 'context' => 'inline', |
| 23 | ], |
| 24 | // the wikitext is embedded into a JSON attribute, processing in a new frame seems to be the right move |
| 25 | // to avoid DSR failures |
| 26 | 'processInNewFrame' => true, |
| 27 | 'clearDSROffsets' => true, |
| 28 | ], false ); |
| 29 | return $this->extApi->domToHtml( $dom, false, true ); |
| 30 | } |
| 31 | } |