]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - vendor/wikimedia/remex-html/RemexHtml/TreeBuilder/InTextarea.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / vendor / wikimedia / remex-html / RemexHtml / TreeBuilder / InTextarea.php
1 <?php
2
3 namespace RemexHtml\TreeBuilder;
4 use RemexHtml\Tokenizer\Attributes;
5
6 /**
7  * This is not a tree builder state in the spec. I added it to handle the
8  * "next token" references in textarea. If the first token is a newline, it is
9  * ignored. Then we switch the dispatcher to the "text" mode regardless, which
10  * is the correct mode for parsing textarea elements.
11  */
12 class InTextarea extends InsertionMode {
13         public function characters( $text, $start, $length, $sourceStart, $sourceLength ) {
14                 if ( $length > 0 && $text[$start] === "\n" ) {
15                         // Ignore initial line break
16                         $start++;
17                         $length--;
18                         $sourceStart++;
19                         $sourceLength--;
20                 }
21                 $mode = $this->dispatcher->switchMode( Dispatcher::TEXT );
22                 if ( $length ) {
23                         $mode->characters( $text, $start, $length, $sourceStart, $sourceLength );
24                 }
25         }
26
27         public function endDocument( $pos ) {
28                 $this->dispatcher->switchMode( Dispatcher::TEXT )
29                         ->endDocument( $pos );
30         }
31
32         public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) {
33                 $this->dispatcher->switchMode( Dispatcher::TEXT )
34                         ->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength );
35         }
36
37         public function endTag( $name, $sourceStart, $sourceLength ) {
38                 $this->dispatcher->switchMode( Dispatcher::TEXT )
39                         ->endTag( $name, $sourceStart, $sourceLength );
40         }
41
42         public function doctype( $name, $public, $system, $quirks, $sourceStart, $sourceLength ) {
43                 $this->dispatcher->switchMode( Dispatcher::TEXT )
44                         ->doctype( $name, $public, $system, $quirks, $sourceStart, $sourceLength );
45         }
46
47         public function comment( $text, $sourceStart, $sourceLength ) {
48                 $this->dispatcher->switchMode( Dispatcher::TEXT )
49                         ->comment( $text, $sourceStart, $sourceLength );
50         }
51 }