]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - vendor/wikimedia/remex-html/RemexHtml/Tokenizer/TokenGeneratorHandler.php
MediaWiki 1.30.2
[autoinstalls/mediawiki.git] / vendor / wikimedia / remex-html / RemexHtml / Tokenizer / TokenGeneratorHandler.php
1 <?php
2
3 namespace RemexHtml\Tokenizer;
4
5 /**
6  * The handler which converts events to tokens arrays for TokenGenerator
7  */
8 class TokenGeneratorHandler implements TokenHandler {
9         public $tokens = [];
10
11         public function startDocument( Tokenizer $tokenizer, $fragmentNamespace, $fragmentName ) {
12                 $this->tokens[] = [
13                         'type' => 'startDocument',
14                         'fragmentNamespace' => $fragmentNamespace,
15                         'fragmentName' => $fragmentName
16                 ];
17         }
18
19         public function endDocument( $pos ) {
20                 $this->tokens[] = [ 'type' => 'endDocument' ];
21         }
22
23         public function error( $text, $pos ) {
24                 $this->tokens[] = [
25                         'type' => 'error',
26                         'text' => $text,
27                         'sourceStart' => $pos
28                 ];
29         }
30
31         public function characters( $text, $start, $length, $sourceStart, $sourceLength ) {
32                 $this->tokens[] = [
33                         'type' => 'text',
34                         'text' => $text,
35                         'start' => $start,
36                         'length' => $length,
37                         'sourceStart' => $sourceStart,
38                         'sourceLength' => $sourceLength ];
39         }
40
41         public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) {
42                 $this->tokens[] = [
43                         'type' => 'startTag',
44                         'name' => $name,
45                         'attrs' => $attrs,
46                         'selfClose' => $selfClose,
47                         'sourceStart' => $sourceStart,
48                         'sourceLength' => $sourceLength ];
49         }
50
51         public function endTag( $name, $sourceStart, $sourceLength ) {
52                 $this->tokens[] = [
53                         'type' => 'endTag',
54                         'name' => $name,
55                         'sourceStart' => $sourceStart,
56                         'sourceLength' => $sourceLength ];
57         }
58
59         public function doctype( $name, $public, $system, $quirks, $sourceStart, $sourceLength ) {
60                 $this->tokens[] = [
61                         'type' => 'doctype',
62                         'name' => $name,
63                         'public' => $public,
64                         'system' => $system,
65                         'quirks' => $quirks ];
66         }
67
68         public function comment( $text, $sourceStart, $sourceLength ) {
69                 $this->tokens[] = [
70                         'type' => 'comment',
71                         'text' => $text,
72                         'sourceStart' => $sourceStart,
73                         'sourceLength' => $sourceLength ];
74         }
75 }