Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 42 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
| InTableText | |
0.00% |
0 / 42 |
|
0.00% |
0 / 8 |
210 | |
0.00% |
0 / 1 |
| characters | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| doctype | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| comment | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| startTag | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| endTag | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| endDocument | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| flush | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| processPendingCharacters | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
42 | |||
| 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 table text" insertion mode |
| 10 | */ |
| 11 | class InTableText extends InsertionMode { |
| 12 | /** @inheritDoc */ |
| 13 | public function characters( $text, $start, $length, $sourceStart, $sourceLength ) { |
| 14 | $handleNonNull = function ( $text, $start, $length, $sourceStart, $sourceLength ) { |
| 15 | $this->builder->pendingTableCharacters[] = [ |
| 16 | $text, $start, $length, $sourceStart, $sourceLength ]; |
| 17 | }; |
| 18 | if ( !$this->builder->ignoreNulls ) { |
| 19 | $this->stripNulls( $handleNonNull, $text, $start, $length, |
| 20 | $sourceStart, $sourceLength ); |
| 21 | } else { |
| 22 | $handleNonNull( $text, $start, $length, $sourceStart, $sourceLength ); |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | /** @inheritDoc */ |
| 27 | public function doctype( $name, $public, $system, $quirks, $sourceStart, $sourceLength ) { |
| 28 | $this->processPendingCharacters(); |
| 29 | $this->dispatcher->restoreMode() |
| 30 | ->doctype( $name, $public, $system, $quirks, $sourceStart, $sourceLength ); |
| 31 | } |
| 32 | |
| 33 | /** @inheritDoc */ |
| 34 | public function comment( $text, $sourceStart, $sourceLength ) { |
| 35 | $this->processPendingCharacters(); |
| 36 | $this->dispatcher->restoreMode() |
| 37 | ->comment( $text, $sourceStart, $sourceLength ); |
| 38 | } |
| 39 | |
| 40 | /** @inheritDoc */ |
| 41 | public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) { |
| 42 | $this->processPendingCharacters(); |
| 43 | $this->dispatcher->restoreMode() |
| 44 | ->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength ); |
| 45 | } |
| 46 | |
| 47 | /** @inheritDoc */ |
| 48 | public function endTag( $name, $sourceStart, $sourceLength ) { |
| 49 | $this->processPendingCharacters(); |
| 50 | $this->dispatcher->restoreMode() |
| 51 | ->endTag( $name, $sourceStart, $sourceLength ); |
| 52 | } |
| 53 | |
| 54 | /** @inheritDoc */ |
| 55 | public function endDocument( $pos ) { |
| 56 | $this->processPendingCharacters(); |
| 57 | $this->dispatcher->restoreMode() |
| 58 | ->endDocument( $pos ); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Flush the pending table text and restore the mode |
| 63 | */ |
| 64 | public function flush() { |
| 65 | $this->processPendingCharacters(); |
| 66 | $this->dispatcher->restoreMode(); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Common code for the "anything else" case. Process the pending table |
| 71 | * character tokens. |
| 72 | */ |
| 73 | protected function processPendingCharacters() { |
| 74 | $builder = $this->builder; |
| 75 | $allSpace = true; |
| 76 | foreach ( $builder->pendingTableCharacters as $token ) { |
| 77 | [ $text, $start, $length, $sourceStart, $sourceLength ] = $token; |
| 78 | if ( strspn( $text, "\t\n\f\r ", $start, $length ) !== $length ) { |
| 79 | $allSpace = false; |
| 80 | } |
| 81 | } |
| 82 | if ( $allSpace ) { |
| 83 | foreach ( $builder->pendingTableCharacters as $token ) { |
| 84 | [ $text, $start, $length, $sourceStart, $sourceLength ] = $token; |
| 85 | $builder->insertCharacters( $text, $start, $length, $sourceStart, $sourceLength ); |
| 86 | } |
| 87 | } else { |
| 88 | $builder->fosterParenting = true; |
| 89 | foreach ( $builder->pendingTableCharacters as $token ) { |
| 90 | [ $text, $start, $length, $sourceStart, $sourceLength ] = $token; |
| 91 | $builder->error( 'invalid characters in table text, fostering', $sourceStart ); |
| 92 | $this->dispatcher->inBody->characters( $text, $start, $length, |
| 93 | $sourceStart, $sourceLength ); |
| 94 | } |
| 95 | $builder->fosterParenting = false; |
| 96 | } |
| 97 | } |
| 98 | } |