Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
BehaviorSwitchHandler | |
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
onBehaviorSwitch | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
onTag | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | declare( strict_types = 1 ); |
3 | |
4 | namespace Wikimedia\Parsoid\Wt2Html\TT; |
5 | |
6 | use Wikimedia\Parsoid\Tokens\KV; |
7 | use Wikimedia\Parsoid\Tokens\SelfclosingTagTk; |
8 | use Wikimedia\Parsoid\Tokens\Token; |
9 | use Wikimedia\Parsoid\Wt2Html\TokenTransformManager; |
10 | |
11 | /** |
12 | * Handler for behavior switches, like '__TOC__' and similar. |
13 | */ |
14 | class BehaviorSwitchHandler extends TokenHandler { |
15 | |
16 | public function __construct( TokenTransformManager $manager, array $options ) { |
17 | parent::__construct( $manager, $options ); |
18 | } |
19 | |
20 | /** |
21 | * Main handler. |
22 | * See {@link TokenTransformManager#addTransform}'s transformation parameter. |
23 | * |
24 | * @param Token $token |
25 | * @return TokenHandlerResult |
26 | */ |
27 | public function onBehaviorSwitch( Token $token ): TokenHandlerResult { |
28 | $env = $this->env; |
29 | $magicWord = $env->getSiteConfig()->getMagicWordForBehaviorSwitch( $token->attribs[0]->v ); |
30 | $env->setBehaviorSwitch( $magicWord, true ); |
31 | $metaToken = new SelfclosingTagTk( |
32 | 'meta', |
33 | [ new KV( 'property', 'mw:PageProp/' . $magicWord ) ], |
34 | clone $token->dataParsoid |
35 | ); |
36 | |
37 | return new TokenHandlerResult( [ $metaToken ] ); |
38 | } |
39 | |
40 | /** |
41 | * @inheritDoc |
42 | */ |
43 | public function onTag( Token $token ): ?TokenHandlerResult { |
44 | return $token->getName() === 'behavior-switch' ? $this->onBehaviorSwitch( $token ) : null; |
45 | } |
46 | } |