You are here

protected function Tokenizer::tagName in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/masterminds/html5/src/HTML5/Parser/Tokenizer.php \Masterminds\HTML5\Parser\Tokenizer::tagName()

Consume a tag name and body. 8.2.4.10

1 call to Tokenizer::tagName()
Tokenizer::tagOpen in vendor/masterminds/html5/src/HTML5/Parser/Tokenizer.php
Emit a tagStart event on encountering a tag.

File

vendor/masterminds/html5/src/HTML5/Parser/Tokenizer.php, line 357

Class

Tokenizer
The HTML5 tokenizer.

Namespace

Masterminds\HTML5\Parser

Code

protected function tagName() {
  $tok = $this->scanner
    ->current();
  if (!ctype_alpha($tok)) {
    return false;
  }

  // We know this is at least one char.
  $name = strtolower($this->scanner
    ->charsWhile(":_-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
  $attributes = array();
  $selfClose = false;

  // Handle attribute parse exceptions here so that we can
  // react by trying to build a sensible parse tree.
  try {
    do {
      $this->scanner
        ->whitespace();
      $this
        ->attribute($attributes);
    } while (!$this
      ->isTagEnd($selfClose));
  } catch (ParseError $e) {
    $selfClose = false;
  }
  $mode = $this->events
    ->startTag($name, $attributes, $selfClose);

  // Should we do this? What does this buy that selfClose doesn't?
  if ($selfClose) {
    $this->events
      ->endTag($name);
  }
  elseif (is_int($mode)) {

    // fprintf(STDOUT, "Event response says move into mode %d for tag %s", $mode, $name);
    $this
      ->setTextMode($mode, $name);
  }
  $this->scanner
    ->next();
  return true;
}