Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 57 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| InTemplate | |
0.00% |
0 / 57 |
|
0.00% |
0 / 4 |
756 | |
0.00% |
0 / 1 |
| characters | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| startTag | |
0.00% |
0 / 37 |
|
0.00% |
0 / 1 |
462 | |||
| endTag | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| endDocument | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | declare( strict_types = 1 ); |
| 3 | |
| 4 | namespace Wikimedia\RemexHtml\TreeBuilder; |
| 5 | |
| 6 | use Wikimedia\RemexHtml\Tokenizer\Attributes; |
| 7 | |
| 8 | /** |
| 9 | * The "in template" insertion mode |
| 10 | */ |
| 11 | class InTemplate extends InsertionMode { |
| 12 | /** @inheritDoc */ |
| 13 | public function characters( $text, $start, $length, $sourceStart, $sourceLength ) { |
| 14 | $this->dispatcher->inBody->characters( |
| 15 | $text, $start, $length, $sourceStart, $sourceLength ); |
| 16 | } |
| 17 | |
| 18 | /** @inheritDoc */ |
| 19 | public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) { |
| 20 | $dispatcher = $this->dispatcher; |
| 21 | |
| 22 | switch ( $name ) { |
| 23 | case 'base': |
| 24 | case 'basefont': |
| 25 | case 'bgsound': |
| 26 | case 'link': |
| 27 | case 'meta': |
| 28 | case 'noframes': |
| 29 | case 'script': |
| 30 | case 'style': |
| 31 | case 'template': |
| 32 | case 'title': |
| 33 | $dispatcher->inHead->startTag( |
| 34 | $name, $attrs, $selfClose, $sourceStart, $sourceLength ); |
| 35 | return; |
| 36 | |
| 37 | case 'caption': |
| 38 | case 'colgroup': |
| 39 | case 'tbody': |
| 40 | case 'tfoot': |
| 41 | case 'thead': |
| 42 | $mode = Dispatcher::IN_TABLE; |
| 43 | break; |
| 44 | |
| 45 | case 'col': |
| 46 | $mode = Dispatcher::IN_COLUMN_GROUP; |
| 47 | break; |
| 48 | |
| 49 | case 'tr': |
| 50 | $mode = Dispatcher::IN_TABLE_BODY; |
| 51 | break; |
| 52 | |
| 53 | case 'td': |
| 54 | case 'th': |
| 55 | $mode = Dispatcher::IN_ROW; |
| 56 | break; |
| 57 | |
| 58 | default: |
| 59 | $mode = Dispatcher::IN_BODY; |
| 60 | break; |
| 61 | } |
| 62 | |
| 63 | $dispatcher->templateModeStack->pop(); |
| 64 | $dispatcher->templateModeStack->push( $mode ); |
| 65 | $dispatcher->switchMode( $mode ) |
| 66 | ->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength ); |
| 67 | } |
| 68 | |
| 69 | /** @inheritDoc */ |
| 70 | public function endTag( $name, $sourceStart, $sourceLength ) { |
| 71 | $dispatcher = $this->dispatcher; |
| 72 | |
| 73 | switch ( $name ) { |
| 74 | case 'template': |
| 75 | $dispatcher->inHead->endTag( $name, $sourceStart, $sourceLength ); |
| 76 | break; |
| 77 | |
| 78 | default: |
| 79 | $this->builder->error( "unexpected </$name> in template, ignoring", $sourceStart ); |
| 80 | return; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | /** @inheritDoc */ |
| 85 | public function endDocument( $pos ) { |
| 86 | $builder = $this->builder; |
| 87 | $stack = $builder->stack; |
| 88 | $dispatcher = $this->dispatcher; |
| 89 | |
| 90 | if ( !$stack->hasTemplate() ) { |
| 91 | $builder->stopParsing( $pos ); |
| 92 | return; |
| 93 | } |
| 94 | |
| 95 | $builder->error( "unexpected end of file in template", $pos ); |
| 96 | $builder->popAllUpToName( 'template', $pos, 0 ); |
| 97 | $builder->afe->clearToMarker(); |
| 98 | $dispatcher->templateModeStack->pop(); |
| 99 | $dispatcher->reset() |
| 100 | ->endDocument( $pos ); |
| 101 | } |
| 102 | } |