3 namespace RemexHtml\TreeBuilder;
4 use RemexHtml\Tokenizer\Attributes;
7 * The "in table text" insertion mode
9 class InTableText extends InsertionMode {
10 public function characters( $text, $start, $length, $sourceStart, $sourceLength ) {
11 $handleNonNull = function ( $text, $start, $length, $sourceStart, $sourceLength ) {
12 $this->builder->pendingTableCharacters[] = [
13 $text, $start, $length, $sourceStart, $sourceLength ];
15 if ( !$this->builder->ignoreNulls ) {
16 $this->stripNulls( $handleNonNull, $text, $start, $length,
17 $sourceStart, $sourceLength );
19 $handleNonNull( $text, $start, $length, $sourceStart, $sourceLength );
23 public function doctype( $name, $public, $system, $quirks, $sourceStart, $sourceLength ) {
24 $this->processPendingCharacters();
25 $this->dispatcher->restoreMode()
26 ->doctype( $name, $public, $system, $quirks, $sourceStart, $sourceLength );
29 public function comment( $text, $sourceStart, $sourceLength ) {
30 $this->processPendingCharacters();
31 $this->dispatcher->restoreMode()
32 ->comment( $text, $sourceStart, $sourceLength );
35 public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) {
36 $this->processPendingCharacters();
37 $this->dispatcher->restoreMode()
38 ->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength );
41 public function endTag( $name, $sourceStart, $sourceLength ) {
42 $this->processPendingCharacters();
43 $this->dispatcher->restoreMode()
44 ->endTag( $name, $sourceStart, $sourceLength );
47 public function endDocument( $pos ) {
48 $this->processPendingCharacters();
49 $this->dispatcher->restoreMode()
50 ->endDocument( $pos );
54 * Common code for the "anything else" case. Process the pending table
57 protected function processPendingCharacters() {
58 $builder = $this->builder;
60 foreach ( $builder->pendingTableCharacters as $token ) {
61 list( $text, $start, $length, $sourceStart, $sourceLength ) = $token;
62 if ( strspn( $text, "\t\n\f\r ", $start, $length ) !== $length ) {
67 foreach ( $builder->pendingTableCharacters as $token ) {
68 list( $text, $start, $length, $sourceStart, $sourceLength ) = $token;
69 $builder->insertCharacters( $text, $start, $length, $sourceStart, $sourceLength );
72 $builder->fosterParenting = true;
73 foreach ( $builder->pendingTableCharacters as $token ) {
74 list( $text, $start, $length, $sourceStart, $sourceLength ) = $token;
75 $builder->error( 'invalid characters in table text, fostering', $sourceStart );
76 $this->dispatcher->inBody->characters( $text, $start, $length,
77 $sourceStart, $sourceLength );
79 $builder->fosterParenting = false;