Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
55.56% covered (warning)
55.56%
10 / 18
33.33% covered (danger)
33.33%
2 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
InTextarea
55.56% covered (warning)
55.56%
10 / 18
33.33% covered (danger)
33.33%
2 / 6
16.11
0.00% covered (danger)
0.00%
0 / 1
 characters
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
4
 endDocument
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 startTag
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 endTag
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 doctype
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 comment
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace Wikimedia\RemexHtml\TreeBuilder;
4
5use 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 */
13class InTextarea extends InsertionMode {
14    public function characters( $text, $start, $length, $sourceStart, $sourceLength ) {
15        if ( $length > 0 && $text[$start] === "\n" ) {
16            // Ignore initial line break
17            $start++;
18            $length--;
19            $sourceStart++;
20            $sourceLength--;
21        }
22        $mode = $this->dispatcher->switchMode( Dispatcher::TEXT );
23        if ( $length ) {
24            $mode->characters( $text, $start, $length, $sourceStart, $sourceLength );
25        }
26    }
27
28    public function endDocument( $pos ) {
29        $this->dispatcher->switchMode( Dispatcher::TEXT )
30            ->endDocument( $pos );
31    }
32
33    public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) {
34        $this->dispatcher->switchMode( Dispatcher::TEXT )
35            ->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength );
36    }
37
38    public function endTag( $name, $sourceStart, $sourceLength ) {
39        $this->dispatcher->switchMode( Dispatcher::TEXT )
40            ->endTag( $name, $sourceStart, $sourceLength );
41    }
42
43    public function doctype( $name, $public, $system, $quirks, $sourceStart, $sourceLength ) {
44        $this->dispatcher->switchMode( Dispatcher::TEXT )
45            ->doctype( $name, $public, $system, $quirks, $sourceStart, $sourceLength );
46    }
47
48    public function comment( $text, $sourceStart, $sourceLength ) {
49        $this->dispatcher->switchMode( Dispatcher::TEXT )
50            ->comment( $text, $sourceStart, $sourceLength );
51    }
52}