3 namespace RemexHtml\Tokenizer;
6 * A TokenHandler which collects events from the Tokenizer and generates an
7 * array compatible with the html5lib tokenizer tests.
9 class TestTokenHandler implements TokenHandler {
12 public function getTokens() {
16 public function startDocument( Tokenizer $tokenizer, $fns, $fn ) {
19 public function endDocument( $pos ) {
22 public function error( $text, $pos ) {
23 $this->tokens[] = 'ParseError';
26 public function characters( $text, $start, $length, $sourceStart, $sourceLength ) {
27 $this->tokens[] = [ 'Character', substr( $text, $start, $length ) ];
30 public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) {
31 $attrArray = $attrs->getValues();
33 $this->tokens[] = [ 'StartTag', $name, $attrArray, $selfClose ];
35 $this->tokens[] = [ 'StartTag', $name, $attrArray ];
39 public function endTag( $name, $sourceStart, $sourceLength ) {
40 $this->tokens[] = [ 'EndTag', $name ];
43 public function doctype( $name, $public, $system, $quirks, $sourceStart, $sourceLength ) {
44 $this->tokens[] = [ 'DOCTYPE', $name, $public, $system, !$quirks ];
47 public function comment( $text, $sourceStart, $sourceLength ) {
48 $this->tokens[] = [ 'Comment', $text ];