Debian Codegraph @

vendor/wikimedia/parsoid/src/Ext/LST/LST.php

raw
1 <?php
2 declare( strict_types = 1 );
3
4 namespace Wikimedia\Parsoid\Ext\LST;
5
6 use Wikimedia\Parsoid\DOM\Element;
7 use Wikimedia\Parsoid\Ext\DOMDataUtils;
8 use Wikimedia\Parsoid\Ext\DOMUtils;
9 use Wikimedia\Parsoid\Ext\ExtensionModule;
10 use Wikimedia\Parsoid\Ext\ExtensionTagHandler;
11 use Wikimedia\Parsoid\Ext\ParsoidExtensionAPI;
12 use Wikimedia\Parsoid\Utils\DOMCompat;
13
14 class LST extends ExtensionTagHandler implements ExtensionModule {
15
16 /** @inheritDoc */
17 public function getConfig(): array {
18 return [
19 'name' => 'LST',
20 'tags' => [
21 [
22 'name' => 'labeledsectiontransclusion',
23 'handler' => self::class,
24 ],
25 [
26 'name' => 'labeledsectiontransclusion/begin',
27 'handler' => self::class,
28 ],
29 [
30 'name' => 'labeledsectiontransclusion/end',
31 'handler' => self::class,
32 ]
33 ]
34 ];
35 }
36
37 /** @inheritDoc */
38 public function domToWikitext(
39 ParsoidExtensionAPI $extApi, Element $node, bool $wrapperUnmodified
40 ) {
41 // TODO: We're keeping this serial handler around to remain backwards
42 // compatible with stored content version 1.3.0 and below. Remove it
43 // when those versions are no longer supported.
44
45 $dp = DOMDataUtils::getDataParsoid( $node );
46 $src = null;
47 $content = DOMCompat::getAttribute( $node, 'content' ) ?? '';
48 if ( isset( $dp->src ) ) {
49 $src = $dp->src;
50 } elseif ( DOMUtils::matchTypeOf( $node, '/begin/' ) ) {
51 $src = '<section begin="' . $content . '" />';
52 } elseif ( DOMUtils::matchTypeOf( $node, '/end/' ) ) {
53 $src = '<section end="' . $content . '" />';
54 } else {
55 $extApi->log( 'error', 'LST <section> without content in: ' .
56 DOMCompat::getOuterHTML( $node ) );
57 $src = '<section />';
58 }
59 return $src;
60 }
61
62 }