Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 68 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| AfterHead | |
0.00% |
0 / 68 |
|
0.00% |
0 / 4 |
702 | |
0.00% |
0 / 1 |
| characters | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
12 | |||
| startTag | |
0.00% |
0 / 38 |
|
0.00% |
0 / 1 |
272 | |||
| endTag | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
42 | |||
| endDocument | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | declare( strict_types = 1 ); |
| 3 | |
| 4 | namespace Wikimedia\RemexHtml\TreeBuilder; |
| 5 | |
| 6 | use Wikimedia\RemexHtml\Tokenizer\Attributes; |
| 7 | use Wikimedia\RemexHtml\Tokenizer\PlainAttributes; |
| 8 | |
| 9 | /** |
| 10 | * The "after head" insertion mode |
| 11 | */ |
| 12 | class AfterHead extends InsertionMode { |
| 13 | /** @inheritDoc */ |
| 14 | public function characters( $text, $start, $length, $sourceStart, $sourceLength ) { |
| 15 | $builder = $this->builder; |
| 16 | $dispatcher = $this->dispatcher; |
| 17 | |
| 18 | // Insert whitespace |
| 19 | [ $part1, $part2 ] = $this->splitInitialMatch( |
| 20 | true, "\t\n\f\r ", $text, $start, $length, $sourceStart, $sourceLength ); |
| 21 | [ $start, $length, $sourceStart, $sourceLength ] = $part1; |
| 22 | if ( $length ) { |
| 23 | $builder->insertCharacters( $text, $start, $length, |
| 24 | $sourceStart, $sourceLength ); |
| 25 | } |
| 26 | |
| 27 | // Switch mode on non-whitespace |
| 28 | [ $start, $length, $sourceStart, $sourceLength ] = $part2; |
| 29 | if ( $length ) { |
| 30 | $builder->insertElement( 'body', new PlainAttributes, false, $sourceStart, 0 ); |
| 31 | $dispatcher->switchMode( Dispatcher::IN_BODY ) |
| 32 | ->characters( $text, $start, $length, $sourceStart, $sourceLength ); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | /** @inheritDoc */ |
| 37 | public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) { |
| 38 | $builder = $this->builder; |
| 39 | $stack = $builder->stack; |
| 40 | $dispatcher = $this->dispatcher; |
| 41 | |
| 42 | switch ( $name ) { |
| 43 | case 'html': |
| 44 | $dispatcher->inBody->startTag( $name, $attrs, $selfClose, |
| 45 | $sourceStart, $sourceLength ); |
| 46 | break; |
| 47 | |
| 48 | case 'body': |
| 49 | $builder->insertElement( $name, $attrs, false, $sourceStart, $sourceLength ); |
| 50 | $builder->framesetOK = false; |
| 51 | $dispatcher->switchMode( Dispatcher::IN_BODY ); |
| 52 | break; |
| 53 | |
| 54 | case 'frameset': |
| 55 | $builder->insertElement( $name, $attrs, false, $sourceStart, $sourceLength ); |
| 56 | $dispatcher->switchMode( Dispatcher::IN_FRAMESET ); |
| 57 | break; |
| 58 | |
| 59 | case 'base': |
| 60 | case 'basefont': |
| 61 | case 'bgsound': |
| 62 | case 'link': |
| 63 | case 'meta': |
| 64 | case 'noframes': |
| 65 | case 'script': |
| 66 | case 'style': |
| 67 | case 'template': |
| 68 | case 'title': |
| 69 | $builder->error( "unexpected <$name> after </head>, accepting", $sourceStart ); |
| 70 | $stack->push( $builder->headElement ); |
| 71 | $dispatcher->inHead->startTag( |
| 72 | $name, $attrs, $selfClose, $sourceStart, $sourceLength ); |
| 73 | $stack->remove( $builder->headElement ); |
| 74 | break; |
| 75 | |
| 76 | case 'head': |
| 77 | $builder->error( "unexpected <head> after </head>, ignoring", $sourceStart ); |
| 78 | return; |
| 79 | |
| 80 | default: |
| 81 | $builder->insertElement( 'body', new PlainAttributes, false, $sourceStart, 0 ); |
| 82 | $dispatcher->switchMode( Dispatcher::IN_BODY ) |
| 83 | ->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength ); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | /** @inheritDoc */ |
| 88 | public function endTag( $name, $sourceStart, $sourceLength ) { |
| 89 | $builder = $this->builder; |
| 90 | $dispatcher = $this->dispatcher; |
| 91 | |
| 92 | switch ( $name ) { |
| 93 | case 'template': |
| 94 | $dispatcher->inHead->endTag( $name, $sourceStart, $sourceLength ); |
| 95 | break; |
| 96 | |
| 97 | case 'body': |
| 98 | case 'html': |
| 99 | case 'br': |
| 100 | $builder->insertElement( 'body', new PlainAttributes, false, $sourceStart, 0 ); |
| 101 | $dispatcher->switchMode( Dispatcher::IN_BODY ) |
| 102 | ->endTag( $name, $sourceStart, $sourceLength ); |
| 103 | break; |
| 104 | |
| 105 | default: |
| 106 | $builder->error( "unexpected </$name> after head, ignoring", $sourceStart ); |
| 107 | return; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | /** @inheritDoc */ |
| 112 | public function endDocument( $pos ) { |
| 113 | $this->builder->insertElement( 'body', new PlainAttributes, false, $pos, 0 ); |
| 114 | $this->dispatcher->switchMode( Dispatcher::IN_BODY ) |
| 115 | ->endDocument( $pos ); |
| 116 | } |
| 117 | } |