3 namespace RemexHtml\TreeBuilder;
4 use RemexHtml\Tokenizer\Attributes;
7 * The "in column group" insertion mode
9 class InColumnGroup extends InsertionMode {
10 public function characters( $text, $start, $length, $sourceStart, $sourceLength ) {
11 list( $part1, $part2 ) = $this->splitInitialMatch(
12 true, "\t\n\f\r ", $text, $start, $length, $sourceStart, $sourceLength );
14 list( $start, $length, $sourceStart, $sourceLength ) = $part1;
15 if ( $length !== 0 ) {
16 $this->builder->insertCharacters( $text, $start, $length,
17 $sourceStart, $sourceLength );
20 list( $start, $length, $sourceStart, $sourceLength ) = $part2;
22 if ( $length === 0 ) {
23 // All done with this sequence
27 // Handle non-whitespace as "anything else"
28 $builder = $this->builder;
29 $stack = $builder->stack;
30 if ( $stack->current->htmlName !== 'colgroup' ) {
31 $builder->error( 'text should close the colgroup but another element is open',
36 $builder->pop( $sourceStart, 0 );
38 $this->dispatcher->switchMode( Dispatcher::IN_TABLE )
39 ->characters( $text, $start, $length, $sourceStart, $sourceLength );
42 public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) {
43 $dispatcher = $this->dispatcher;
44 $builder = $this->builder;
45 $stack = $builder->stack;
49 $dispatcher->inBody->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength );
53 $dispatcher->ack = true;
54 $builder->insertElement( $name, $attrs, true, $sourceStart, $sourceLength );
58 $dispatcher->inHead->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength );
62 if ( $stack->current->htmlName !== 'colgroup' ) {
63 $builder->error( 'start tag should close the colgroup but another element is open',
68 $builder->pop( $sourceStart, 0 );
70 $this->dispatcher->switchMode( Dispatcher::IN_TABLE )
71 ->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength );
75 public function endTag( $name, $sourceStart, $sourceLength ) {
76 $dispatcher = $this->dispatcher;
77 $builder = $this->builder;
78 $stack = $builder->stack;
82 if ( $stack->current->htmlName !== 'colgroup' ) {
83 $builder->error( '</colgroup> found but another element is open, ignoring',
87 $builder->pop( $sourceStart, $sourceLength );
88 $dispatcher->switchMode( Dispatcher::IN_TABLE );
92 $builder->error( '</col> found in column group mode, ignoring', $sourceStart );
96 $dispatcher->inHead->endTag( $name, $sourceStart, $sourceLength );
100 if ( $stack->current->htmlName !== 'colgroup' ) {
101 $builder->error( 'non-matching end tag should close the colgroup ' .
102 ' but another element is open', $sourceStart );
106 $builder->pop( $sourceStart, 0 );
108 $dispatcher->switchMode( Dispatcher::IN_TABLE )
109 ->endTag( $name, $sourceStart, $sourceLength );
113 public function endDocument( $pos ) {
114 $this->dispatcher->inBody->endDocument( $pos );