Debian Codegraph @

vendor/wikimedia/remex-html/src/TreeBuilder/InPre.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 pre/listing. The specified mode for parsing the
10 * pre/listing is saved before entering this mode. This mode checks if the
11 * first token is a newline, and then switches to the correct mode regardless.
12 */
13 class InPre extends InsertionMode {
14 /** @inheritDoc */
15 public function characters( $text, $start, $length, $sourceStart, $sourceLength ) {
16 if ( $length > 0 && $text[$start] === "\n" ) {
17 $start++;
18 $length--;
19 $sourceStart++;
20 $sourceLength--;
21 }
22 $mode = $this->dispatcher->restoreMode();
23 if ( $length ) {
24 $mode->characters( $text, $start, $length, $sourceStart, $sourceLength );
25 }
26 }
27
28 /** @inheritDoc */
29 public function endDocument( $pos ) {
30 $this->dispatcher->restoreMode()
31 ->endDocument( $pos );
32 }
33
34 /** @inheritDoc */
35 public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) {
36 $this->dispatcher->restoreMode()
37 ->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength );
38 }
39
40 /** @inheritDoc */
41 public function endTag( $name, $sourceStart, $sourceLength ) {
42 $this->dispatcher->restoreMode()
43 ->endTag( $name, $sourceStart, $sourceLength );
44 }
45
46 /** @inheritDoc */
47 public function doctype( $name, $public, $system, $quirks, $sourceStart, $sourceLength ) {
48 $this->dispatcher->restoreMode()
49 ->doctype( $name, $public, $system, $quirks, $sourceStart, $sourceLength );
50 }
51
52 /** @inheritDoc */
53 public function comment( $text, $sourceStart, $sourceLength ) {
54 $this->dispatcher->restoreMode()
55 ->comment( $text, $sourceStart, $sourceLength );
56 }
57 }