Debian Codegraph @

vendor/wikimedia/remex-html/src/TreeBuilder/InTextarea.php

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