Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
I18nTag
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 2
12
0.00% covered (danger)
0.00%
0 / 1
 sourceToDom
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
6
 getConfig
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2declare( strict_types = 1 );
3
4namespace Wikimedia\Parsoid\ParserTests;
5
6use Wikimedia\Parsoid\DOM\DocumentFragment;
7use Wikimedia\Parsoid\Ext\ExtensionModule;
8use Wikimedia\Parsoid\Ext\ExtensionTagHandler;
9use Wikimedia\Parsoid\Ext\ParsoidExtensionAPI;
10
11class I18nTag extends ExtensionTagHandler implements ExtensionModule {
12    /** @inheritDoc */
13    public function sourceToDom(
14        ParsoidExtensionAPI $extApi, string $content, array $args
15    ): DocumentFragment {
16        $tag = $extApi->extTag;
17        if ( $tag->getName() === 'i18ntag' ) {
18            return $extApi->createPageContentI18nFragment( $content, null );
19        } else {
20            $frag = $extApi->getTopLevelDoc()->createDocumentFragment();
21            $span = $extApi->getTopLevelDoc()->createElement( 'span' );
22            $frag->appendChild( $span );
23            $span->appendChild( $extApi->getTopLevelDoc()->createTextNode( $content ) );
24            $extApi->addInterfaceI18nAttribute( $span, 'message', $args[0]->v, null );
25            return $frag;
26        }
27    }
28
29    /** @inheritDoc */
30    public function getConfig(): array {
31        return [
32            'name' => 'I18nTag',
33            'tags' => [
34                [ 'name' => 'i18ntag', 'handler' => self::class ],
35                [ 'name' => 'i18nattr', 'handler' => self::class ],
36            ],
37        ];
38    }
39}