]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - vendor/wikimedia/remex-html/RemexHtml/TreeBuilder/InColumnGroup.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / vendor / wikimedia / remex-html / RemexHtml / TreeBuilder / InColumnGroup.php
1 <?php
2
3 namespace RemexHtml\TreeBuilder;
4 use RemexHtml\Tokenizer\Attributes;
5
6 /**
7  * The "in column group" insertion mode
8  */
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 );
13
14                 list( $start, $length, $sourceStart, $sourceLength ) = $part1;
15                 if ( $length !== 0 ) {
16                         $this->builder->insertCharacters( $text, $start, $length,
17                                 $sourceStart, $sourceLength );
18                 }
19
20                 list( $start, $length, $sourceStart, $sourceLength ) = $part2;
21
22                 if ( $length === 0 ) {
23                         // All done with this sequence
24                         return;
25                 }
26
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',
32                                 $sourceStart );
33                         // Ignore
34                         return;
35                 } else {
36                         $builder->pop( $sourceStart, 0 );
37                 }
38                 $this->dispatcher->switchMode( Dispatcher::IN_TABLE )
39                         ->characters( $text, $start, $length, $sourceStart, $sourceLength );
40         }
41
42         public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) {
43                 $dispatcher = $this->dispatcher;
44                 $builder = $this->builder;
45                 $stack = $builder->stack;
46
47                 switch ( $name ) {
48                 case 'html':
49                         $dispatcher->inBody->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength );
50                         break;
51
52                 case 'col':
53                         $dispatcher->ack = true;
54                         $builder->insertElement( $name, $attrs, true, $sourceStart, $sourceLength );
55                         break;
56
57                 case 'template':
58                         $dispatcher->inHead->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength );
59                         break;
60
61                 default:
62                         if ( $stack->current->htmlName !== 'colgroup' ) {
63                                 $builder->error( 'start tag should close the colgroup but another element is open',
64                                         $sourceStart );
65                                 // Ignore
66                                 return;
67                         } else {
68                                 $builder->pop( $sourceStart, 0 );
69                         }
70                         $this->dispatcher->switchMode( Dispatcher::IN_TABLE )
71                                 ->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength );
72                 }
73         }
74
75         public function endTag( $name, $sourceStart, $sourceLength ) {
76                 $dispatcher = $this->dispatcher;
77                 $builder = $this->builder;
78                 $stack = $builder->stack;
79
80                 switch ( $name ) {
81                 case 'colgroup':
82                         if ( $stack->current->htmlName !== 'colgroup' ) {
83                                 $builder->error( '</colgroup> found but another element is open, ignoring',
84                                         $sourceStart );
85                                 return;
86                         }
87                         $builder->pop( $sourceStart, $sourceLength );
88                         $dispatcher->switchMode( Dispatcher::IN_TABLE );
89                         break;
90
91                 case 'col':
92                         $builder->error( '</col> found in column group mode, ignoring', $sourceStart );
93                         break;
94
95                 case 'template':
96                         $dispatcher->inHead->endTag( $name, $sourceStart, $sourceLength );
97                         break;
98
99                 default:
100                         if ( $stack->current->htmlName !== 'colgroup' ) {
101                                 $builder->error( 'non-matching end tag should close the colgroup ' .
102                                         ' but another element is open', $sourceStart );
103                                 // Ignore
104                                 return;
105                         } else {
106                                 $builder->pop( $sourceStart, 0 );
107                         }
108                         $dispatcher->switchMode( Dispatcher::IN_TABLE )
109                                 ->endTag( $name, $sourceStart, $sourceLength );
110                 }
111         }
112
113         public function endDocument( $pos ) {
114                 $this->dispatcher->inBody->endDocument( $pos );
115         }
116 }