Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| XMLTagBasedHandler | |
0.00% |
0 / 11 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 1 |
| onTag | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| process | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
30 | |||
| 1 | <?php |
| 2 | declare( strict_types = 1 ); |
| 3 | |
| 4 | namespace Wikimedia\Parsoid\Wt2Html\TT; |
| 5 | |
| 6 | use Wikimedia\Parsoid\Tokens\Token; |
| 7 | use Wikimedia\Parsoid\Tokens\XMLTagTk; |
| 8 | |
| 9 | /** |
| 10 | * These handlers process wikitext tags that are not dependent |
| 11 | * on line semantics. They can be processed independent of the |
| 12 | * token stream for the most part. |
| 13 | * |
| 14 | * Ex: templates, extensions, links |
| 15 | * |
| 16 | * They only need to support onTag handlers. |
| 17 | */ |
| 18 | abstract class XMLTagBasedHandler extends TokenHandler { |
| 19 | /** |
| 20 | * The handler may choose to process only specific kinds of XMLTagTk tokens. |
| 21 | * For example, a list handler may only process 'listitem' TagTk tokens. |
| 22 | * |
| 23 | * @param XMLTagTk $token tag to be processed |
| 24 | * @return ?array<string|Token> |
| 25 | * - null indicates that the token was unmodified and the |
| 26 | * token will be added to the output. |
| 27 | * - an array indicates the token was transformed and the |
| 28 | * tokens in the array will be added to the output. |
| 29 | */ |
| 30 | public function onTag( XMLTagTk $token ): ?array { |
| 31 | return null; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * At present, compound tokens don't pass through here because this class |
| 36 | * is only used in TokenTransform2 and compound tokens appear in |
| 37 | * TokenTransform3. If ever that changes, we probably want to process |
| 38 | * them similar to how UniversalTokenHandler does. |
| 39 | * |
| 40 | * @inheritDoc |
| 41 | */ |
| 42 | public function process( array $tokens ): array { |
| 43 | $accum = []; |
| 44 | foreach ( $tokens as $token ) { |
| 45 | $res = null; |
| 46 | if ( $token instanceof XMLTagTk ) { |
| 47 | $res = $this->onTag( $token ); |
| 48 | } |
| 49 | if ( $res === null ) { |
| 50 | $accum[] = $token; |
| 51 | } else { |
| 52 | // Avoid array_merge() -- see https://w.wiki/3zvE |
| 53 | foreach ( $res as $t ) { |
| 54 | $accum[] = $t; |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | return $accum; |
| 59 | } |
| 60 | } |