Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 18 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| InTextarea | |
0.00% |
0 / 18 |
|
0.00% |
0 / 6 |
90 | |
0.00% |
0 / 1 |
| characters | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
| endDocument | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| startTag | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| endTag | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| doctype | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| comment | |
0.00% |
0 / 2 |
|
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 | |
| 8 | /** |
| 9 | * This is not a tree builder state in the spec. I added it to handle the |
| 10 | * "next token" references in textarea. If the first token is a newline, it is |
| 11 | * ignored. Then we switch the dispatcher to the "text" mode regardless, which |
| 12 | * is the correct mode for parsing textarea elements. |
| 13 | */ |
| 14 | class InTextarea extends InsertionMode { |
| 15 | /** @inheritDoc */ |
| 16 | public function characters( $text, $start, $length, $sourceStart, $sourceLength ) { |
| 17 | if ( $length > 0 && $text[$start] === "\n" ) { |
| 18 | // Ignore initial line break |
| 19 | $start++; |
| 20 | $length--; |
| 21 | $sourceStart++; |
| 22 | $sourceLength--; |
| 23 | } |
| 24 | $mode = $this->dispatcher->switchMode( Dispatcher::TEXT ); |
| 25 | if ( $length ) { |
| 26 | $mode->characters( $text, $start, $length, $sourceStart, $sourceLength ); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | /** @inheritDoc */ |
| 31 | public function endDocument( $pos ) { |
| 32 | $this->dispatcher->switchMode( Dispatcher::TEXT ) |
| 33 | ->endDocument( $pos ); |
| 34 | } |
| 35 | |
| 36 | /** @inheritDoc */ |
| 37 | public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) { |
| 38 | $this->dispatcher->switchMode( Dispatcher::TEXT ) |
| 39 | ->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength ); |
| 40 | } |
| 41 | |
| 42 | /** @inheritDoc */ |
| 43 | public function endTag( $name, $sourceStart, $sourceLength ) { |
| 44 | $this->dispatcher->switchMode( Dispatcher::TEXT ) |
| 45 | ->endTag( $name, $sourceStart, $sourceLength ); |
| 46 | } |
| 47 | |
| 48 | /** @inheritDoc */ |
| 49 | public function doctype( $name, $public, $system, $quirks, $sourceStart, $sourceLength ) { |
| 50 | $this->dispatcher->switchMode( Dispatcher::TEXT ) |
| 51 | ->doctype( $name, $public, $system, $quirks, $sourceStart, $sourceLength ); |
| 52 | } |
| 53 | |
| 54 | /** @inheritDoc */ |
| 55 | public function comment( $text, $sourceStart, $sourceLength ) { |
| 56 | $this->dispatcher->switchMode( Dispatcher::TEXT ) |
| 57 | ->comment( $text, $sourceStart, $sourceLength ); |
| 58 | } |
| 59 | } |