]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - vendor/wikimedia/remex-html/RemexHtml/Tokenizer/TokenGeneratorHandler.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / vendor / wikimedia / remex-html / RemexHtml / Tokenizer / TokenGeneratorHandler.php
diff --git a/vendor/wikimedia/remex-html/RemexHtml/Tokenizer/TokenGeneratorHandler.php b/vendor/wikimedia/remex-html/RemexHtml/Tokenizer/TokenGeneratorHandler.php
new file mode 100644 (file)
index 0000000..29f94f0
--- /dev/null
@@ -0,0 +1,75 @@
+<?php
+
+namespace RemexHtml\Tokenizer;
+
+/**
+ * The handler which converts events to tokens arrays for TokenGenerator
+ */
+class TokenGeneratorHandler implements TokenHandler {
+       public $tokens = [];
+
+       public function startDocument( Tokenizer $tokenizer, $fragmentNamespace, $fragmentName ) {
+               $this->tokens[] = [
+                       'type' => 'startDocument',
+                       'fragmentNamespace' => $fragmentNamespace,
+                       'fragmentName' => $fragmentName
+               ];
+       }
+
+       public function endDocument( $pos ) {
+               $this->tokens[] = [ 'type' => 'endDocument' ];
+       }
+
+       public function error( $text, $pos ) {
+               $this->tokens[] = [
+                       'type' => 'error',
+                       'text' => $text,
+                       'sourceStart' => $pos
+               ];
+       }
+
+       public function characters( $text, $start, $length, $sourceStart, $sourceLength ) {
+               $this->tokens[] = [
+                       'type' => 'text',
+                       'text' => $text,
+                       'start' => $start,
+                       'length' => $length,
+                       'sourceStart' => $sourceStart,
+                       'sourceLength' => $sourceLength ];
+       }
+
+       public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) {
+               $this->tokens[] = [
+                       'type' => 'startTag',
+                       'name' => $name,
+                       'attrs' => $attrs,
+                       'selfClose' => $selfClose,
+                       'sourceStart' => $sourceStart,
+                       'sourceLength' => $sourceLength ];
+       }
+
+       public function endTag( $name, $sourceStart, $sourceLength ) {
+               $this->tokens[] = [
+                       'type' => 'endTag',
+                       'name' => $name,
+                       'sourceStart' => $sourceStart,
+                       'sourceLength' => $sourceLength ];
+       }
+
+       public function doctype( $name, $public, $system, $quirks, $sourceStart, $sourceLength ) {
+               $this->tokens[] = [
+                       'type' => 'doctype',
+                       'name' => $name,
+                       'public' => $public,
+                       'system' => $system,
+                       'quirks' => $quirks ];
+       }
+
+       public function comment( $text, $sourceStart, $sourceLength ) {
+               $this->tokens[] = [
+                       'type' => 'comment',
+                       'text' => $text,
+                       'sourceStart' => $sourceStart,
+                       'sourceLength' => $sourceLength ];
+       }
+}