You are here

public function DOMTreeBuilder::text in Zircon Profile 8

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

A unit of parsed character data.

Entities in this text are *already decoded*.

Overrides EventHandler::text

File

vendor/masterminds/html5/src/HTML5/Parser/DOMTreeBuilder.php, line 547

Class

DOMTreeBuilder
Create an HTML5 DOM tree from events.

Namespace

Masterminds\HTML5\Parser

Code

public function text($data) {

  // XXX: Hmmm.... should we really be this strict?
  if ($this->insertMode < static::IM_IN_HEAD) {

    // Per '8.2.5.4.3 The "before head" insertion mode' the characters
    // " \t\n\r\f" should be ignored but no mention of a parse error. This is
    // practical as most documents contain these characters. Other text is not
    // expected here so recording a parse error is necessary.
    $dataTmp = trim($data, " \t\n\r\f");
    if (!empty($dataTmp)) {

      // fprintf(STDOUT, "Unexpected insert mode: %d", $this->insertMode);
      $this
        ->parseError("Unexpected text. Ignoring: " . $dataTmp);
    }
    return;
  }

  // fprintf(STDOUT, "Appending text %s.", $data);
  $node = $this->doc
    ->createTextNode($data);
  $this->current
    ->appendChild($node);
}