]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - vendor/wikimedia/remex-html/RemexHtml/Tokenizer/TestTokenHandler.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / vendor / wikimedia / remex-html / RemexHtml / Tokenizer / TestTokenHandler.php
1 <?php
2
3 namespace RemexHtml\Tokenizer;
4
5 /**
6  * A TokenHandler which collects events from the Tokenizer and generates an
7  * array compatible with the html5lib tokenizer tests.
8  */
9 class TestTokenHandler implements TokenHandler {
10         private $tokens = [];
11
12         public function getTokens() {
13                 return $this->tokens;
14         }
15
16         public function startDocument( Tokenizer $tokenizer, $fns, $fn ) {
17         }
18
19         public function endDocument( $pos ) {
20         }
21
22         public function error( $text, $pos ) {
23                 $this->tokens[] = 'ParseError';
24         }
25
26         public function characters( $text, $start, $length, $sourceStart, $sourceLength ) {
27                 $this->tokens[] = [ 'Character', substr( $text, $start, $length ) ];
28         }
29
30         public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) {
31                 $attrArray = $attrs->getValues();
32                 if ( $selfClose ) {
33                         $this->tokens[] = [ 'StartTag', $name, $attrArray, $selfClose ];
34                 } else {
35                         $this->tokens[] = [ 'StartTag', $name, $attrArray ];
36                 }
37         }
38
39         public function endTag( $name, $sourceStart, $sourceLength ) {
40                 $this->tokens[] = [ 'EndTag', $name ];
41         }
42
43         public function doctype( $name, $public, $system, $quirks, $sourceStart, $sourceLength ) {
44                 $this->tokens[] = [ 'DOCTYPE', $name, $public, $system, !$quirks ];
45         }
46
47         public function comment( $text, $sourceStart, $sourceLength ) {
48                 $this->tokens[] = [ 'Comment', $text ];
49         }
50 }