Lines Matching full:token
77 private $token; variable in HTML5
531 /* In any case, emit the input character as a character token. Stay
569 /* In any case, emit the input character as a character token.
580 Emit an end-of-file token. */
586 the text and emit it as a character token. */
599 otherwise would also be treated as a character token and emit it
600 as a single character token. Stay in the data state. */
621 // If nothing is returned, emit a U+0026 AMPERSAND character token.
622 // Otherwise, emit the character token that was returned.
643 U+003C LESS-THAN SIGN character token and switch to the data
679 Create a new start tag token, set its tag name to the lowercase
681 point), then switch to the tag name state. (Don't emit the token
683 $this->token = array(
693 Parse error. Emit a U+003C LESS-THAN SIGN character token and a
694 U+003E GREATER-THAN SIGN character token. Switch to the data state. */
711 Parse error. Emit a U+003C LESS-THAN SIGN character token and
740 the last start tag token emitted (case insensitively), or if they do but
751 token, a U+002F SOLIDUS character token, and switch to the data state
771 Create a new end tag token, set its tag name to the lowercase version
773 switch to the tag name state. (Don't emit the token yet; further details
775 $this->token = array(
789 Parse error. Emit a U+003C LESS-THAN SIGN character token and a U+002F
790 SOLIDUS character token. Reconsume the EOF character in the data state. */
825 Emit the current tag token. Switch to the data state. */
826 $this->emitToken($this->token);
831 Parse error. Emit the current tag token. Reconsume the EOF
833 $this->emitToken($this->token);
846 Append the current input character to the current tag token's tag name.
848 $this->token['name'] .= strtolower($char);
870 Emit the current tag token. Switch to the data state. */
871 $this->emitToken($this->token);
882 Parse error. Emit the current tag token. Reconsume the EOF
884 $this->emitToken($this->token);
891 Start a new attribute in the current tag token. Set that attribute's
894 $this->token['attr'][] = array(
925 Emit the current tag token. Switch to the data state. */
926 $this->emitToken($this->token);
937 Parse error. Emit the current tag token. Reconsume the EOF
939 $this->emitToken($this->token);
948 $last = count($this->token['attr']) - 1;
949 $this->token['attr'][$last]['name'] .= strtolower($char);
977 Emit the current tag token. Switch to the data state. */
978 $this->emitToken($this->token);
989 Parse error. Emit the current tag token. Reconsume the EOF
991 $this->emitToken($this->token);
998 Start a new attribute in the current tag token. Set that attribute's
1001 $this->token['attr'][] = array(
1044 Emit the current tag token. Switch to the data state. */
1045 $this->emitToken($this->token);
1052 $last = count($this->token['attr']) - 1;
1053 $this->token['attr'][$last]['value'] .= $char;
1077 Parse error. Emit the current tag token. Reconsume the character
1079 $this->emitToken($this->token);
1088 $last = count($this->token['attr']) - 1;
1089 $this->token['attr'][$last]['value'] .= $char;
1113 Parse error. Emit the current tag token. Reconsume the character
1115 $this->emitToken($this->token);
1124 $last = count($this->token['attr']) - 1;
1125 $this->token['attr'][$last]['value'] .= $char;
1153 Emit the current tag token. Switch to the data state. */
1154 $this->emitToken($this->token);
1161 $last = count($this->token['attr']) - 1;
1162 $this->token['attr'][$last]['value'] .= $char;
1174 // current attribute's value. Otherwise, emit the character token that
1180 $last = count($this->token['attr']) - 1;
1181 $this->token['attr'][$last]['value'] .= $char;
1188 a comment token whose data is the concatenation of all the characters
1193 the file (EOF), the token is empty.) */
1216 characters, consume those two characters, create a comment token whose
1221 $this->token = array(
1255 /* Parse error. Emit the comment token. Reconsume the EOF character
1257 $this->emitToken($this->token);
1263 /* Append the input character to the comment token's data. Stay in
1265 $this->token['data'] .= $char;
1282 /* Parse error. Emit the comment token. Reconsume the EOF character
1284 $this->emitToken($this->token);
1291 character to the comment token's data. Switch to the comment state. */
1292 $this->token['data'] .= '-' . $char;
1304 $this->emitToken($this->token);
1308 $this->token['data'] .= '-';
1311 $this->emitToken($this->token);
1316 $this->token['data'] .= '--' . $char;
1346 $this->token = array(
1378 $this->token = array(
1398 $this->emitToken($this->token);
1402 $this->token['name'] .= strtoupper($char);
1405 $this->emitToken($this->token);
1410 $this->token['name'] .= $char;
1413 $this->token['error'] = ($this->token['name'] === 'HTML')
1428 $this->emitToken($this->token);
1432 $this->emitToken($this->token);
1437 $this->token['error'] = true;
1449 $this->emitToken($this->token);
1453 $this->emitToken($this->token);
1549 // Return a character token for the character corresponding to the
1554 private function emitToken($token) argument
1556 $emit = $this->tree->emitToken($token);
1561 } elseif ($token['type'] === self::ENDTAG) {
1713 public function emitToken($token) argument
1717 return $this->initPhase($token);
1720 return $this->rootElementPhase($token);
1723 return $this->mainPhase($token);
1726 return $this->trailingEndPhase($token);
1731 private function initPhase($token) argument
1733 /* Initially, the tree construction stage must handle each token
1736 /* A DOCTYPE token that is marked as being in error
1737 A comment token
1738 A start tag token
1739 An end tag token
1740 A character token that is not one of one of U+0009 CHARACTER TABULATION,
1743 An end-of-file token */
1744 if ((isset($token['error']) && $token['error']) ||
1745 $token['type'] === HTML5::COMMENT ||
1746 $token['type'] === HTML5::STARTTAG ||
1747 $token['type'] === HTML5::ENDTAG ||
1748 $token['type'] === HTML5::EOF ||
1749 ($token['type'] === HTML5::CHARACTR && isset($token['data']) &&
1750 !preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data']))
1758 return $this->rootElementPhase($token);
1760 /* A DOCTYPE token marked as being correct */
1761 } elseif (isset($token['error']) && !$token['error']) {
1763 attribute set to the name given in the DOCTYPE token (which will be
1772 /* A character token that is one of one of U+0009 CHARACTER TABULATION,
1775 } elseif (isset($token['data']) && preg_match(
1777 $token['data']
1781 $text = $this->dom->createTextNode($token['data']);
1786 private function rootElementPhase($token) argument
1788 /* After the initial phase, as each token is emitted from the tokenisation
1791 /* A DOCTYPE token */
1792 if ($token['type'] === HTML5::DOCTYPE) {
1793 // Parse error. Ignore the token.
1795 /* A comment token */
1796 } elseif ($token['type'] === HTML5::COMMENT) {
1798 attribute set to the data given in the comment token. */
1799 $comment = $this->dom->createComment($token['data']);
1802 /* A character token that is one of one of U+0009 CHARACTER TABULATION,
1805 } elseif ($token['type'] === HTML5::CHARACTR &&
1806 preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])
1809 $text = $this->dom->createTextNode($token['data']);
1812 /* A character token that is not one of U+0009 CHARACTER TABULATION,
1815 A start tag token
1816 An end tag token
1817 An end-of-file token */
1818 } elseif (($token['type'] === HTML5::CHARACTR &&
1819 !preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) ||
1820 $token['type'] === HTML5::STARTTAG ||
1821 $token['type'] === HTML5::ENDTAG ||
1822 $token['type'] === HTML5::EOF
1826 phase and reprocess the current token. */
1832 return $this->mainPhase($token);
1836 private function mainPhase($token) argument
1840 /* A DOCTYPE token */
1841 if ($token['type'] === HTML5::DOCTYPE) {
1842 // Parse error. Ignore the token.
1844 /* A start tag token with the tag name "html" */
1845 } elseif ($token['type'] === HTML5::STARTTAG && $token['name'] === 'html') {
1846 /* If this start tag token was not the first start tag token, then
1849 /* For each attribute on the token, check to see if the attribute
1853 foreach ($token['attr'] as $attr) {
1859 /* An end-of-file token */
1860 } elseif ($token['type'] === HTML5::EOF) {
1869 return $this->beforeHead($token);
1872 return $this->inHead($token);
1875 return $this->afterHead($token);
1878 return $this->inBody($token);
1881 return $this->inTable($token);
1884 return $this->inCaption($token);
1887 return $this->inColumnGroup($token);
1890 return $this->inTableBody($token);
1893 return $this->inRow($token);
1896 return $this->inCell($token);
1899 return $this->inSelect($token);
1902 return $this->afterBody($token);
1905 return $this->inFrameset($token);
1908 return $this->afterFrameset($token);
1911 return $this->trailingEndPhase($token);
1917 private function beforeHead($token) argument
1919 /* Handle the token as follows: */
1921 /* A character token that is one of one of U+0009 CHARACTER TABULATION,
1924 if ($token['type'] === HTML5::CHARACTR &&
1925 preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])
1928 $this->insertText($token['data']);
1930 /* A comment token */
1931 } elseif ($token['type'] === HTML5::COMMENT) {
1933 set to the data given in the comment token. */
1934 $this->insertComment($token['data']);
1936 /* A start tag token with the tag name "head" */
1937 } elseif ($token['type'] === HTML5::STARTTAG && $token['name'] === 'head') {
1938 /* Create an element for the token, append the new element to the
1940 $element = $this->insertElement($token);
1948 /* A start tag token whose tag name is one of: "base", "link", "meta",
1950 Or a character token that is not one of U+0009 CHARACTER TABULATION,
1952 or U+0020 SPACE. Or any other start tag token */
1953 } elseif ($token['type'] === HTML5::STARTTAG ||
1954 ($token['type'] === HTML5::ENDTAG && $token['name'] === 'html') ||
1955 ($token['type'] === HTML5::CHARACTR && !preg_match(
1957 $token['data']
1960 /* Act as if a start tag token with the tag name "head" and no
1961 attributes had been seen, then reprocess the current token. */
1970 return $this->inHead($token);
1973 } elseif ($token['type'] === HTML5::ENDTAG) {
1974 /* Parse error. Ignore the token. */
1978 private function inHead($token) argument
1980 /* Handle the token as follows: */
1982 /* A character token that is one of one of U+0009 CHARACTER TABULATION,
1989 if (($token['type'] === HTML5::CHARACTR &&
1990 preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) || (
1991 $token['type'] === HTML5::CHARACTR && in_array(
1997 $this->insertText($token['data']);
1999 /* A comment token */
2000 } elseif ($token['type'] === HTML5::COMMENT) {
2002 set to the data given in the comment token. */
2003 $this->insertComment($token['data']);
2005 } elseif ($token['type'] === HTML5::ENDTAG &&
2006 in_array($token['name'], array('title', 'style', 'script'))
2012 } elseif ($token['type'] === HTML5::STARTTAG && $token['name'] === 'title') {
2013 /* Create an element for the token and append the new element to the
2017 $element = $this->insertElement($token, false);
2021 $element = $this->insertElement($token);
2028 } elseif ($token['type'] === HTML5::STARTTAG && $token['name'] === 'style') {
2029 /* Create an element for the token and append the new element to the
2033 $element = $this->insertElement($token, false);
2037 $this->insertElement($token);
2044 } elseif ($token['type'] === HTML5::STARTTAG && $token['name'] === 'script') {
2045 /* Create an element for the token. */
2046 $element = $this->insertElement($token, false);
2053 } elseif ($token['type'] === HTML5::STARTTAG && in_array(
2054 $token['name'],
2058 /* Create an element for the token and append the new element to the
2062 $element = $this->insertElement($token, false);
2067 $this->insertElement($token);
2071 } elseif ($token['type'] === HTML5::ENDTAG && $token['name'] === 'head') {
2086 } elseif (($token['type'] === HTML5::STARTTAG && $token['name'] === 'head') ||
2087 ($token['type'] === HTML5::ENDTAG && $token['name'] !== 'html')
2089 // Parse error. Ignore the token.
2094 token with the tag name "head" had been seen. */
2108 /* Then, reprocess the current token. */
2109 return $this->afterHead($token);
2113 private function afterHead($token) argument
2115 /* Handle the token as follows: */
2117 /* A character token that is one of one of U+0009 CHARACTER TABULATION,
2120 if ($token['type'] === HTML5::CHARACTR &&
2121 preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])
2124 $this->insertText($token['data']);
2126 /* A comment token */
2127 } elseif ($token['type'] === HTML5::COMMENT) {
2129 set to the data given in the comment token. */
2130 $this->insertComment($token['data']);
2132 /* A start tag token with the tag name "body" */
2133 } elseif ($token['type'] === HTML5::STARTTAG && $token['name'] === 'body') {
2134 /* Insert a body element for the token. */
2135 $this->insertElement($token);
2140 /* A start tag token with the tag name "frameset" */
2141 } elseif ($token['type'] === HTML5::STARTTAG && $token['name'] === 'frameset') {
2142 /* Insert a frameset element for the token. */
2143 $this->insertElement($token);
2148 /* A start tag token whose tag name is one of: "base", "link", "meta",
2150 } elseif ($token['type'] === HTML5::STARTTAG && in_array(
2151 $token['name'],
2156 reprocess the token. */
2158 return $this->inHead($token);
2162 /* Act as if a start tag token with the tag name "body" and no
2163 attributes had been seen, and then reprocess the current token. */
2172 return $this->inBody($token);
2176 private function inBody($token) argument
2178 /* Handle the token as follows: */
2180 switch ($token['type']) {
2181 /* A character token */
2186 /* Append the token's character to the current node. */
2187 $this->insertText($token['data']);
2190 /* A comment token */
2193 attribute set to the data given in the comment token. */
2194 $this->insertComment($token['data']);
2198 switch ($token['name']) {
2199 /* A start tag token whose tag name is one of: "script",
2203 /* Process the token as if the insertion mode had been "in
2205 return $this->inHead($token);
2208 /* A start tag token whose tag name is one of: "base", "link",
2214 /* Parse error. Process the token as if the insertion mode
2216 return $this->inHead($token);
2219 /* A start tag token with the tag name "body" */
2223 elements has only one node on it, then ignore the token.
2228 /* Otherwise, for each attribute on the token, check to see
2234 foreach ($token['attr'] as $attr) {
2269 /* Insert an HTML element for the token. */
2270 $this->insertElement($token);
2276 token with a parse error. */
2294 /* Insert an HTML element for the token, and set the
2296 $element = $this->insertElement($token);
2329 if ($token['name'] === $node->tagName || ($token['name'] !== 'li'
2350 name as the token's. */
2351 $this->insertElement($token);
2354 /* A start tag token whose tag name is "plaintext" */
2368 /* Insert an HTML element for the token. */
2369 $this->insertElement($token);
2402 /* Insert an HTML element for the token. */
2403 $this->insertElement($token);
2437 /* Insert an HTML element for the token. */
2438 $el = $this->insertElement($token);
2462 /* Insert an HTML element for the token. */
2463 $el = $this->insertElement($token);
2470 /* A start tag token whose tag name is "button" */
2474 name "button" had been seen, then reprocess the token. (We don't
2488 /* Insert an HTML element for the token. */
2489 $this->insertElement($token);
2496 /* A start tag token whose tag name is one of: "marquee", "object" */
2502 /* Insert an HTML element for the token. */
2503 $this->insertElement($token);
2510 /* A start tag token whose tag name is "xmp" */
2515 /* Insert an HTML element for the token. */
2516 $this->insertElement($token);
2535 /* Insert an HTML element for the token. */
2536 $this->insertElement($token);
2556 /* Insert an HTML element for the token. */
2557 $this->insertElement($token);
2576 /* Insert an HTML element for the token. */
2577 $this->insertElement($token);
2585 /* Parse error. Change the token's tag name to "img" and
2587 $token['name'] = 'img';
2588 return $this->inBody($token);
2596 /* Insert an input element for the token. */
2597 $element = $this->insertElement($token, false);
2616 then ignore the token. */
2618 /* Act as if a start tag token with the tag name "form" had
2628 /* Act as if a start tag token with the tag name "hr" had
2638 /* Act as if a start tag token with the tag name "p" had
2648 /* Act as if a start tag token with the tag name "label"
2664 /* Act as if a start tag token with the tag name "input"
2666 token, except with the "name" attribute set to the value
2668 $attr = $token['attr'];
2686 /* Act as if an end tag token with the tag name "label"
2695 /* Act as if an end tag token with the tag name "p" had
2704 /* Act as if a start tag token with the tag name "hr" had
2713 /* Act as if an end tag token with the tag name "form" had
2726 $this->insertElement($token);
2738 $this->insertElement($token);
2749 /* Insert an HTML element for the token. */
2750 $this->insertElement($token);
2773 // Parse error. Ignore the token.
2791 /* A start tag token not covered by the previous entries */
2796 $this->insertElement($token, true, true);
2802 switch ($token['name']) {
2806 not a body element, this is a parse error. Ignore the token.
2824 then, if that token wasn't ignored, reprocess the current
2825 token. */
2833 return $this->afterBody($token);
2852 with the same tag name as that of the token, then generate
2854 if ($this->elementInScope($token['name'])) {
2858 the same tag name as that of the token, then this
2863 scope with the same tag name as that of the token,
2867 if ($this->stack[$n]->nodeName === $token['name']) {
2879 with the same tag name as that of the token, then generate
2881 if ($this->elementInScope($token['name'])) {
2886 if (end($this->stack)->nodeName !== $token['name']) {
2888 same tag name as that of the token, then this is a parse
2894 the same tag name as that of the token pop that element
2933 whose tag name matches the tag name of the token, then
2935 same tag name as the token. */
2936 if ($this->elementInScope($token['name'])) {
2937 $this->generateImpliedEndTags(array($token['name']));
2940 tag name as the token, then this is a parse error. */
2944 whose tag name matches the tag name of the token, then
2948 if ($this->stack[$n]->nodeName === $token['name']) {
2974 tag name as that of the token, then this is a parse error. */
3007 * has the same tag name as the token.
3014 } elseif ($this->a_formatting[$a]->tagName === $token['name']) {
3025 these steps. The token is ignored. */
3027 !$this->elementInScope($token['name']))
3212 /* An end tag token whose tag name is one of: "button",
3218 tag name matches the tag name of the token, then generate implied
3220 if ($this->elementInScope($token['name'])) {
3224 tag name as the token, then this is a parse error. */
3228 whose tag name matches the tag name of the token, then pop
3233 if ($this->stack[$n]->nodeName === $token['name']) {
3271 // Parse error. Ignore the token.
3274 /* An end tag token not covered by the previous entries */
3281 /* If node has the same tag name as the end tag token,
3283 if ($token['name'] === $node->nodeName) {
3287 /* If the tag name of the end tag token does not
3304 parse error. Stop this algorithm. The end tag token
3316 private function inTable($token) argument
3320 /* A character token that is one of one of U+0009 CHARACTER TABULATION,
3323 if ($token['type'] === HTML5::CHARACTR &&
3324 preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])
3327 $text = $this->dom->createTextNode($token['data']);
3330 /* A comment token */
3331 } elseif ($token['type'] === HTML5::COMMENT) {
3333 attribute set to the data given in the comment token. */
3334 $comment = $this->dom->createComment($token['data']);
3338 } elseif ($token['type'] === HTML5::STARTTAG &&
3339 $token['name'] === 'caption'
3348 /* Insert an HTML element for the token, then switch the
3350 $this->insertElement($token);
3354 } elseif ($token['type'] === HTML5::STARTTAG &&
3355 $token['name'] === 'colgroup'
3360 /* Insert an HTML element for the token, then switch the
3362 $this->insertElement($token);
3366 } elseif ($token['type'] === HTML5::STARTTAG &&
3367 $token['name'] === 'col'
3377 $this->inColumnGroup($token);
3380 } elseif ($token['type'] === HTML5::STARTTAG && in_array(
3381 $token['name'],
3388 /* Insert an HTML element for the token, then switch the insertion
3390 $this->insertElement($token);
3394 } elseif ($token['type'] === HTML5::STARTTAG &&
3395 in_array($token['name'], array('td', 'th', 'tr'))
3397 /* Act as if a start tag token with the tag name "tbody" had been
3398 seen, then reprocess the current token. */
3407 return $this->inTableBody($token);
3410 } elseif ($token['type'] === HTML5::STARTTAG &&
3411 $token['name'] === 'table'
3413 /* Parse error. Act as if an end tag token with the tag name "table"
3414 had been seen, then, if that token wasn't ignored, reprocess the
3415 current token. */
3423 return $this->mainPhase($token);
3426 } elseif ($token['type'] === HTML5::ENDTAG &&
3427 $token['name'] === 'table'
3430 scope with the same tag name as the token, this is a parse error.
3431 Ignore the token. (innerHTML case) */
3432 if (!$this->elementInScope($token['name'], true)) {
3461 } elseif ($token['type'] === HTML5::ENDTAG && in_array(
3462 $token['name'],
3478 // Parse error. Ignore the token.
3482 /* Parse error. Process the token as if the insertion mode was "in
3524 $this->inBody($token);
3528 private function inCaption($token) argument
3531 if ($token['type'] === HTML5::ENDTAG && $token['name'] === 'caption') {
3533 scope with the same tag name as the token, this is a parse error.
3534 Ignore the token. (innerHTML case) */
3535 if (!$this->elementInScope($token['name'], true)) {
3569 } elseif (($token['type'] === HTML5::STARTTAG && in_array(
3570 $token['name'],
3582 )) || ($token['type'] === HTML5::ENDTAG &&
3583 $token['name'] === 'table')
3586 had been seen, then, if that token wasn't ignored, reprocess the
3587 current token. */
3595 return $this->inTable($token);
3599 } elseif ($token['type'] === HTML5::ENDTAG && in_array(
3600 $token['name'],
3614 // Parse error. Ignore the token.
3618 /* Process the token as if the insertion mode was "in body". */
3619 $this->inBody($token);
3623 private function inColumnGroup($token) argument
3625 /* A character token that is one of one of U+0009 CHARACTER TABULATION,
3628 if ($token['type'] === HTML5::CHARACTR &&
3629 preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])
3632 $text = $this->dom->createTextNode($token['data']);
3635 /* A comment token */
3636 } elseif ($token['type'] === HTML5::COMMENT) {
3638 attribute set to the data given in the comment token. */
3639 $comment = $this->dom->createComment($token['data']);
3643 } elseif ($token['type'] === HTML5::STARTTAG && $token['name'] === 'col') {
3644 /* Insert a col element for the token. Immediately pop the current
3646 $this->insertElement($token);
3650 } elseif ($token['type'] === HTML5::ENDTAG &&
3651 $token['name'] === 'colgroup'
3654 parse error, ignore the token. (innerHTML case) */
3667 } elseif ($token['type'] === HTML5::ENDTAG && $token['name'] === 'col') {
3668 /* Parse error. Ignore the token. */
3673 and then, if that token wasn't ignored, reprocess the current token. */
3681 return $this->inTable($token);
3685 private function inTableBody($token) argument
3690 if ($token['type'] === HTML5::STARTTAG && $token['name'] === 'tr') {
3694 /* Insert a tr element for the token, then switch the insertion
3696 $this->insertElement($token);
3700 } elseif ($token['type'] === HTML5::STARTTAG &&
3701 ($token['name'] === 'th' || $token['name'] === 'td')
3704 been seen, then reprocess the current token. */
3713 return $this->inRow($token);
3716 } elseif ($token['type'] === HTML5::ENDTAG &&
3717 in_array($token['name'], array('tbody', 'tfoot', 'thead'))
3720 scope with the same tag name as the token, this is a parse error.
3721 Ignore the token. */
3722 if (!$this->elementInScope($token['name'], true)) {
3738 } elseif (($token['type'] === HTML5::STARTTAG && in_array(
3739 $token['name'],
3742 ($token['type'] === HTML5::STARTTAG && $token['name'] === 'table')
3746 token. (innerHTML case) */
3757 reprocess the current token. */
3765 return $this->mainPhase($token);
3770 } elseif ($token['type'] === HTML5::ENDTAG && in_array(
3771 $token['name'],
3775 /* Parse error. Ignore the token. */
3779 /* Process the token as if the insertion mode was "in table". */
3780 $this->inTable($token);
3784 private function inRow($token) argument
3789 if ($token['type'] === HTML5::STARTTAG &&
3790 ($token['name'] === 'th' || $token['name'] === 'td')
3795 /* Insert an HTML element for the token, then switch the insertion
3797 $this->insertElement($token);
3805 } elseif ($token['type'] === HTML5::ENDTAG && $token['name'] === 'tr') {
3807 scope with the same tag name as the token, this is a parse error.
3808 Ignore the token. (innerHTML case) */
3809 if (!$this->elementInScope($token['name'], true)) {
3826 } elseif ($token['type'] === HTML5::STARTTAG && in_array(
3827 $token['name'],
3832 if that token wasn't ignored, reprocess the current token. */
3840 return $this->inCell($token);
3843 } elseif ($token['type'] === HTML5::ENDTAG &&
3844 in_array($token['name'], array('tbody', 'tfoot', 'thead'))
3847 scope with the same tag name as the token, this is a parse error.
3848 Ignore the token. */
3849 if (!$this->elementInScope($token['name'], true)) {
3855 been seen, then reprocess the current token. */
3863 return $this->inCell($token);
3868 } elseif ($token['type'] === HTML5::ENDTAG && in_array(
3869 $token['name'],
3873 /* Parse error. Ignore the token. */
3877 /* Process the token as if the insertion mode was "in table". */
3878 $this->inTable($token);
3882 private function inCell($token) argument
3885 if ($token['type'] === HTML5::ENDTAG &&
3886 ($token['name'] === 'td' || $token['name'] === 'th')
3889 scope with the same tag name as that of the token, then this is a
3890 parse error and the token must be ignored. */
3891 if (!$this->elementInScope($token['name'], true)) {
3897 tag name as the token. */
3898 $this->generateImpliedEndTags(array($token['name']));
3901 name as the token, then this is a parse error. */
3905 tag name as the token has been popped from the stack. */
3910 if ($node === $token['name']) {
3926 } elseif ($token['type'] === HTML5::STARTTAG && in_array(
3927 $token['name'],
3942 in table scope, then this is a parse error; ignore the token.
3948 token. */
3951 return $this->inRow($token);
3956 } elseif ($token['type'] === HTML5::STARTTAG && in_array(
3957 $token['name'],
3972 in table scope, then this is a parse error; ignore the token.
3978 token. */
3981 return $this->inRow($token);
3986 } elseif ($token['type'] === HTML5::ENDTAG && in_array(
3987 $token['name'],
3991 /* Parse error. Ignore the token. */
3995 } elseif ($token['type'] === HTML5::ENDTAG && in_array(
3996 $token['name'],
4001 scope with the same tag name as that of the token (which can only
4003 then this is a parse error and the token must be ignored. */
4004 if (!$this->elementInScope($token['name'], true)) {
4008 token. */
4011 return $this->inRow($token);
4016 /* Process the token as if the insertion mode was "in body". */
4017 $this->inBody($token);
4021 private function inSelect($token) argument
4023 /* Handle the token as follows: */
4025 /* A character token */
4026 if ($token['type'] === HTML5::CHARACTR) {
4027 /* Append the token's character to the current node. */
4028 $this->insertText($token['data']);
4030 /* A comment token */
4031 } elseif ($token['type'] === HTML5::COMMENT) {
4033 attribute set to the data given in the comment token. */
4034 $this->insertComment($token['data']);
4036 /* A start tag token whose tag name is "option" */
4037 } elseif ($token['type'] === HTML5::STARTTAG &&
4038 $token['name'] === 'option'
4051 /* Insert an HTML element for the token. */
4052 $this->insertElement($token);
4054 /* A start tag token whose tag name is "optgroup" */
4055 } elseif ($token['type'] === HTML5::STARTTAG &&
4056 $token['name'] === 'optgroup'
4080 /* Insert an HTML element for the token. */
4081 $this->insertElement($token);
4083 /* An end tag token whose tag name is "optgroup" */
4084 } elseif ($token['type'] === HTML5::ENDTAG &&
4085 $token['name'] === 'optgroup'
4106 ignore the token. */
4111 /* An end tag token whose tag name is "option" */
4112 } elseif ($token['type'] === HTML5::ENDTAG &&
4113 $token['name'] === 'option'
4117 ignore the token. */
4123 } elseif ($token['type'] === HTML5::ENDTAG &&
4124 $token['name'] === 'select'
4127 scope with the same tag name as the token, this is a parse error.
4128 Ignore the token. (innerHTML case) */
4129 if (!$this->elementInScope($token['name'], true)) {
4150 } elseif ($token['name'] === 'select' &&
4151 $token['type'] === HTML5::STARTTAG
4153 /* Parse error. Act as if the token had been an end tag with the
4165 $token['name'],
4176 ) && $token['type'] === HTML5::ENDTAG
4182 the same tag name as that of the token, then act as if an end tag
4183 with the tag name "select" had been seen, and reprocess the token.
4184 Otherwise, ignore the token. */
4185 if ($this->elementInScope($token['name'], true)) {
4193 $this->mainPhase($token);
4198 /* Parse error. Ignore the token. */
4202 private function afterBody($token) argument
4204 /* Handle the token as follows: */
4206 /* A character token that is one of one of U+0009 CHARACTER TABULATION,
4209 if ($token['type'] === HTML5::CHARACTR &&
4210 preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])
4212 /* Process the token as it would be processed if the insertion mode
4214 $this->inBody($token);
4216 /* A comment token */
4217 } elseif ($token['type'] === HTML5::COMMENT) {
4220 data given in the comment token. */
4221 $comment = $this->dom->createComment($token['data']);
4225 } elseif ($token['type'] === HTML5::ENDTAG && $token['name'] === 'html') {
4228 ignore the token. (The element will be an html element in this
4237 the token. */
4239 return $this->inBody($token);
4243 private function inFrameset($token) argument
4245 /* Handle the token as follows: */
4247 /* A character token that is one of one of U+0009 CHARACTER TABULATION,
4250 if ($token['type'] === HTML5::CHARACTR &&
4251 preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])
4254 $this->insertText($token['data']);
4256 /* A comment token */
4257 } elseif ($token['type'] === HTML5::COMMENT) {
4259 attribute set to the data given in the comment token. */
4260 $this->insertComment($token['data']);
4263 } elseif ($token['name'] === 'frameset' &&
4264 $token['type'] === HTML5::STARTTAG
4266 $this->insertElement($token);
4269 } elseif ($token['name'] === 'frameset' &&
4270 $token['type'] === HTML5::ENDTAG
4273 parse error; ignore the token. (innerHTML case) */
4290 } elseif ($token['name'] === 'frame' &&
4291 $token['type'] === HTML5::STARTTAG
4293 /* Insert an HTML element for the token. */
4294 $this->insertElement($token);
4300 } elseif ($token['name'] === 'noframes' &&
4301 $token['type'] === HTML5::STARTTAG
4303 /* Process the token as if the insertion mode had been "in body". */
4304 $this->inBody($token);
4308 /* Parse error. Ignore the token. */
4312 private function afterFrameset($token) argument
4314 /* Handle the token as follows: */
4316 /* A character token that is one of one of U+0009 CHARACTER TABULATION,
4319 if ($token['type'] === HTML5::CHARACTR &&
4320 preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])
4323 $this->insertText($token['data']);
4325 /* A comment token */
4326 } elseif ($token['type'] === HTML5::COMMENT) {
4328 attribute set to the data given in the comment token. */
4329 $this->insertComment($token['data']);
4332 } elseif ($token['name'] === 'html' &&
4333 $token['type'] === HTML5::ENDTAG
4339 } elseif ($token['name'] === 'noframes' &&
4340 $token['type'] === HTML5::STARTTAG
4342 /* Process the token as if the insertion mode had been "in body". */
4343 $this->inBody($token);
4347 /* Parse error. Ignore the token. */
4351 private function trailingEndPhase($token) argument
4353 /* After the main phase, as each token is emitted from the tokenisation
4356 /* A DOCTYPE token */
4357 if ($token['type'] === HTML5::DOCTYPE) {
4358 // Parse error. Ignore the token.
4360 /* A comment token */
4361 } elseif ($token['type'] === HTML5::COMMENT) {
4363 attribute set to the data given in the comment token. */
4364 $comment = $this->dom->createComment($token['data']);
4367 /* A character token that is one of one of U+0009 CHARACTER TABULATION,
4370 } elseif ($token['type'] === HTML5::CHARACTR &&
4371 preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])
4373 /* Process the token as it would be processed in the main phase. */
4374 $this->mainPhase($token);
4376 /* A character token that is not one of U+0009 CHARACTER TABULATION,
4378 or U+0020 SPACE. Or a start tag token. Or an end tag token. */
4379 } elseif (($token['type'] === HTML5::CHARACTR &&
4380 preg_match('/^[\t\n\x0b\x0c ]+$/', $token['data'])) ||
4381 $token['type'] === HTML5::STARTTAG || $token['type'] === HTML5::ENDTAG
4384 token. */
4386 return $this->mainPhase($token);
4388 /* An end-of-file token */
4389 } elseif ($token['type'] === HTML5::EOF) {
4394 private function insertElement($token, $append = true, $check = false) argument
4400 $token['name'] = preg_replace('/[^a-z0-9-]/i', '', $token['name']);
4402 $token['name'] = ltrim($token['name'], '-0..9');
4404 if ($token['name'] === '') {
4405 $token['name'] = 'span';
4409 $el = $this->dom->createElement($token['name']);
4411 foreach ($token['attr'] as $attr) {
4769 then act as if an end tag token with that tag name had been seen. */