Lines Matching refs:this

23         $new_html = $this->normalize($html, $config, $context);
24 $new_html = $this->wrapHTML($new_html, $config, $context, false /* no div */);
35 $this->tokenizeDOM(
463 $this->data = $data;
464 $this->char = -1;
465 $this->EOF = strlen($data);
466 $this->tree = new HTML5TreeConstructer;
467 $this->content_model = self::PCDATA;
469 $this->state = 'data';
471 while ($this->state !== null) {
472 $this->{$this->state . 'State'}();
478 return $this->tree->save();
483 return ($this->char < $this->EOF)
484 ? $this->data[$this->char]
490 if ($s + $l < $this->EOF) {
492 return $this->data[$s];
494 return substr($this->data, $s, $l);
501 return preg_replace('#^([' . $char_class . ']+).*#s', '\\1', substr($this->data, $start));
507 $this->char++;
508 $char = $this->char();
510 …if ($char === '&' && ($this->content_model === self::PCDATA || $this->content_model === self::RCDA…
515 $this->state = 'entityData';
524 if (($this->content_model === self::RCDATA || $this->content_model ===
525 self::CDATA) && $this->escape === false &&
526 $this->char >= 3 && $this->character($this->char - 4, 4) === '<!--'
528 $this->escape = true;
533 $this->emitToken(
541 } elseif ($char === '<' && ($this->content_model === self::PCDATA ||
542 (($this->content_model === self::RCDATA ||
543 $this->content_model === self::CDATA) && $this->escape === false))
553 $this->state = 'tagOpen';
562 if (($this->content_model === self::RCDATA ||
563 $this->content_model === self::CDATA) && $this->escape === true &&
564 $this->character($this->char, 3) === '-->'
566 $this->escape = false;
571 $this->emitToken(
578 } elseif ($this->char === $this->EOF) {
581 $this->EOF();
583 } elseif ($this->content_model === self::PLAINTEXT) {
587 $this->emitToken(
590 'data' => substr($this->data, $this->char)
594 $this->EOF();
601 $len = strcspn($this->data, '<&', $this->char);
602 $char = substr($this->data, $this->char, $len);
603 $this->char += $len - 1;
605 $this->emitToken(
612 $this->state = 'data';
619 $entity = $this->entity();
624 $this->emitToken(
632 $this->state = 'data';
637 switch ($this->content_model) {
645 if ($this->character($this->char + 1) === '/') {
646 $this->char++;
647 $this->state = 'closeTagOpen';
650 $this->emitToken(
657 $this->state = 'data';
664 $this->char++;
665 $char = $this->char();
670 $this->state = 'markupDeclarationOpen';
675 $this->state = 'closeTagOpen';
683 $this->token = array(
689 $this->state = 'tagName';
695 $this->emitToken(
702 $this->state = 'data';
707 $this->state = 'bogusComment';
713 $this->emitToken(
720 $this->char--;
721 $this->state = 'data';
729 $next_node = strtolower($this->characters('A-Za-z', $this->char + 1));
730 … $the_same = count($this->tree->stack) > 0 && $next_node === end($this->tree->stack)->nodeName;
732 if (($this->content_model === self::RCDATA || $this->content_model === self::CDATA) &&
735 $this->character($this->char + 1 + strlen($next_node))
736 ) || $this->EOF === $this->char)))
753 $this->emitToken(
760 $this->state = 'data';
766 $this->char++;
767 $char = $this->char();
775 $this->token = array(
780 $this->state = 'tagName';
785 $this->state = 'data';
787 } elseif ($this->char === $this->EOF) {
791 $this->emitToken(
798 $this->char--;
799 $this->state = 'data';
803 $this->state = 'bogusComment';
811 $this->char++;
812 $char = $this->character($this->char);
821 $this->state = 'beforeAttributeName';
826 $this->emitToken($this->token);
827 $this->state = 'data';
829 } elseif ($this->char === $this->EOF) {
833 $this->emitToken($this->token);
835 $this->char--;
836 $this->state = 'data';
842 $this->state = 'beforeAttributeName';
848 $this->token['name'] .= strtolower($char);
849 $this->state = 'tagName';
856 $this->char++;
857 $char = $this->character($this->char);
866 $this->state = 'beforeAttributeName';
871 $this->emitToken($this->token);
872 $this->state = 'data';
878 $this->state = 'beforeAttributeName';
880 } elseif ($this->char === $this->EOF) {
884 $this->emitToken($this->token);
886 $this->char--;
887 $this->state = 'data';
894 $this->token['attr'][] = array(
899 $this->state = 'attributeName';
906 $this->char++;
907 $char = $this->character($this->char);
916 $this->state = 'afterAttributeName';
921 $this->state = 'beforeAttributeValue';
926 $this->emitToken($this->token);
927 $this->state = 'data';
929 } elseif ($char === '/' && $this->character($this->char + 1) !== '>') {
933 $this->state = 'beforeAttributeName';
935 } elseif ($this->char === $this->EOF) {
939 $this->emitToken($this->token);
941 $this->char--;
942 $this->state = 'data';
948 $last = count($this->token['attr']) - 1;
949 $this->token['attr'][$last]['name'] .= strtolower($char);
951 $this->state = 'attributeName';
958 $this->char++;
959 $char = $this->character($this->char);
968 $this->state = 'afterAttributeName';
973 $this->state = 'beforeAttributeValue';
978 $this->emitToken($this->token);
979 $this->state = 'data';
981 } elseif ($char === '/' && $this->character($this->char + 1) !== '>') {
985 $this->state = 'beforeAttributeName';
987 } elseif ($this->char === $this->EOF) {
991 $this->emitToken($this->token);
993 $this->char--;
994 $this->state = 'data';
1001 $this->token['attr'][] = array(
1006 $this->state = 'attributeName';
1013 $this->char++;
1014 $char = $this->character($this->char);
1023 $this->state = 'beforeAttributeValue';
1028 $this->state = 'attributeValueDoubleQuoted';
1034 $this->char--;
1035 $this->state = 'attributeValueUnquoted';
1040 $this->state = 'attributeValueSingleQuoted';
1045 $this->emitToken($this->token);
1046 $this->state = 'data';
1052 $last = count($this->token['attr']) - 1;
1053 $this->token['attr'][$last]['value'] .= $char;
1055 $this->state = 'attributeValueUnquoted';
1062 $this->char++;
1063 $char = $this->character($this->char);
1068 $this->state = 'beforeAttributeName';
1073 $this->entityInAttributeValueState('double');
1075 } elseif ($this->char === $this->EOF) {
1079 $this->emitToken($this->token);
1081 $this->char--;
1082 $this->state = 'data';
1088 $last = count($this->token['attr']) - 1;
1089 $this->token['attr'][$last]['value'] .= $char;
1091 $this->state = 'attributeValueDoubleQuoted';
1098 $this->char++;
1099 $char = $this->character($this->char);
1104 $this->state = 'beforeAttributeName';
1109 $this->entityInAttributeValueState('single');
1111 } elseif ($this->char === $this->EOF) {
1115 $this->emitToken($this->token);
1117 $this->char--;
1118 $this->state = 'data';
1124 $last = count($this->token['attr']) - 1;
1125 $this->token['attr'][$last]['value'] .= $char;
1127 $this->state = 'attributeValueSingleQuoted';
1134 $this->char++;
1135 $char = $this->character($this->char);
1144 $this->state = 'beforeAttributeName';
1149 $this->entityInAttributeValueState();
1154 $this->emitToken($this->token);
1155 $this->state = 'data';
1161 $last = count($this->token['attr']) - 1;
1162 $this->token['attr'][$last]['value'] .= $char;
1164 $this->state = 'attributeValueUnquoted';
1171 $entity = $this->entity();
1180 $last = count($this->token['attr']) - 1;
1181 $this->token['attr'][$last]['value'] .= $char;
1194 $data = $this->characters('^>', $this->char);
1195 $this->emitToken(
1202 $this->char += strlen($data);
1205 $this->state = 'data';
1208 if ($this->char === $this->EOF) {
1209 $this->char = $this->EOF - 1;
1218 if ($this->character($this->char + 1, 2) === '--') {
1219 $this->char += 2;
1220 $this->state = 'comment';
1221 $this->token = array(
1229 } elseif (strtolower($this->character($this->char + 1, 7)) === 'doctype') {
1230 $this->char += 7;
1231 $this->state = 'doctype';
1237 $this->char++;
1238 $this->state = 'bogusComment';
1245 $this->char++;
1246 $char = $this->char();
1251 $this->state = 'commentDash';
1254 } elseif ($this->char === $this->EOF) {
1257 $this->emitToken($this->token);
1258 $this->char--;
1259 $this->state = 'data';
1265 $this->token['data'] .= $char;
1272 $this->char++;
1273 $char = $this->char();
1278 $this->state = 'commentEnd';
1281 } elseif ($this->char === $this->EOF) {
1284 $this->emitToken($this->token);
1285 $this->char--;
1286 $this->state = 'data';
1292 $this->token['data'] .= '-' . $char;
1293 $this->state = 'comment';
1300 $this->char++;
1301 $char = $this->char();
1304 $this->emitToken($this->token);
1305 $this->state = 'data';
1308 $this->token['data'] .= '-';
1310 } elseif ($this->char === $this->EOF) {
1311 $this->emitToken($this->token);
1312 $this->char--;
1313 $this->state = 'data';
1316 $this->token['data'] .= '--' . $char;
1317 $this->state = 'comment';
1324 $this->char++;
1325 $char = $this->char();
1328 $this->state = 'beforeDoctypeName';
1331 $this->char--;
1332 $this->state = 'beforeDoctypeName';
1339 $this->char++;
1340 $char = $this->char();
1346 $this->token = array(
1352 $this->state = 'doctypeName';
1355 $this->emitToken(
1363 $this->state = 'data';
1365 } elseif ($this->char === $this->EOF) {
1366 $this->emitToken(
1374 $this->char--;
1375 $this->state = 'data';
1378 $this->token = array(
1384 $this->state = 'doctypeName';
1391 $this->char++;
1392 $char = $this->char();
1395 $this->state = 'AfterDoctypeName';
1398 $this->emitToken($this->token);
1399 $this->state = 'data';
1402 $this->token['name'] .= strtoupper($char);
1404 } elseif ($this->char === $this->EOF) {
1405 $this->emitToken($this->token);
1406 $this->char--;
1407 $this->state = 'data';
1410 $this->token['name'] .= $char;
1413 $this->token['error'] = ($this->token['name'] === 'HTML')
1421 $this->char++;
1422 $char = $this->char();
1428 $this->emitToken($this->token);
1429 $this->state = 'data';
1431 } elseif ($this->char === $this->EOF) {
1432 $this->emitToken($this->token);
1433 $this->char--;
1434 $this->state = 'data';
1437 $this->token['error'] = true;
1438 $this->state = 'bogusDoctype';
1445 $this->char++;
1446 $char = $this->char();
1449 $this->emitToken($this->token);
1450 $this->state = 'data';
1452 } elseif ($this->char === $this->EOF) {
1453 $this->emitToken($this->token);
1454 $this->char--;
1455 $this->state = 'data';
1464 $start = $this->char;
1472 switch ($this->character($this->char + 1)) {
1478 switch ($this->character($this->char + 1)) {
1505 $this->char++;
1506 $e_name = $this->characters($char_class, $this->char + $char + 1);
1507 $entity = $this->character($start, $this->char);
1519 $e_name = $this->characters('0-9A-Za-z;', $this->char + 1);
1524 $this->char++;
1526 if (in_array($id, $this->entities)) {
1529 $this->char++; // consume extra semicolon
1545 $this->char = $start;
1556 $emit = $this->tree->emitToken($token);
1559 $this->content_model = $emit;
1562 $this->content_model = self::PCDATA;
1568 $this->state = null;
1569 $this->tree->emitToken(
1702 $this->phase = self::INIT_PHASE;
1703 $this->mode = self::BEFOR_HEAD;
1704 $this->dom = new DOMDocument;
1706 $this->dom->encoding = 'UTF-8';
1707 $this->dom->preserveWhiteSpace = true;
1708 $this->dom->substituteEntities = true;
1709 $this->dom->strictErrorChecking = false;
1715 switch ($this->phase) {
1717 return $this->initPhase($token);
1720 return $this->rootElementPhase($token);
1723 return $this->mainPhase($token);
1726 return $this->trailingEndPhase($token);
1757 $this->phase = self::ROOT_PHASE;
1758 return $this->rootElementPhase($token);
1770 $this->phase = self::ROOT_PHASE;
1781 $text = $this->dom->createTextNode($token['data']);
1782 $this->dom->appendChild($text);
1799 $comment = $this->dom->createComment($token['data']);
1800 $this->dom->appendChild($comment);
1809 $text = $this->dom->createTextNode($token['data']);
1810 $this->dom->appendChild($text);
1827 $html = $this->dom->createElement('html');
1828 $this->dom->appendChild($html);
1829 $this->stack[] = $html;
1831 $this->phase = self::MAIN_PHASE;
1832 return $this->mainPhase($token);
1854 if (!$this->stack[0]->hasAttribute($attr['name'])) {
1855 $this->stack[0]->setAttribute($attr['name'], $attr['value']);
1862 $this->generateImpliedEndTags();
1867 switch ($this->mode) {
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);
1928 $this->insertText($token['data']);
1934 $this->insertComment($token['data']);
1940 $element = $this->insertElement($token);
1943 $this->head_pointer = $element;
1946 $this->mode = self::IN_HEAD;
1962 $this->beforeHead(
1970 return $this->inHead($token);
1992 end($this->stack)->nodeName,
1997 $this->insertText($token['data']);
2003 $this->insertComment($token['data']);
2008 array_pop($this->stack);
2016 if ($this->head_pointer !== null) {
2017 $element = $this->insertElement($token, false);
2018 $this->head_pointer->appendChild($element);
2021 $element = $this->insertElement($token);
2032 if ($this->head_pointer !== null) {
2033 $element = $this->insertElement($token, false);
2034 $this->head_pointer->appendChild($element);
2037 $this->insertElement($token);
2046 $element = $this->insertElement($token, false);
2047 $this->head_pointer->appendChild($element);
2061 if ($this->head_pointer !== null) {
2062 $element = $this->insertElement($token, false);
2063 $this->head_pointer->appendChild($element);
2064 array_pop($this->stack);
2067 $this->insertElement($token);
2074 if ($this->head_pointer->isSameNode(end($this->stack))) {
2075 array_pop($this->stack);
2083 $this->mode = self::AFTER_HEAD;
2095 if ($this->head_pointer->isSameNode(end($this->stack))) {
2096 $this->inHead(
2105 $this->mode = self::AFTER_HEAD;
2109 return $this->afterHead($token);
2124 $this->insertText($token['data']);
2130 $this->insertComment($token['data']);
2135 $this->insertElement($token);
2138 $this->mode = self::IN_BODY;
2143 $this->insertElement($token);
2146 $this->mode = self::IN_FRAME;
2157 $this->mode = self::IN_HEAD;
2158 return $this->inHead($token);
2164 $this->afterHead(
2172 return $this->inBody($token);
2184 $this->reconstructActiveFormattingElements();
2187 $this->insertText($token['data']);
2194 $this->insertComment($token['data']);
2205 return $this->inHead($token);
2216 return $this->inHead($token);
2225 if (count($this->stack) === 1 || $this->stack[1]->nodeName !== 'body') {
2235 if (!$this->stack[1]->hasAttribute($attr['name'])) {
2236 $this->stack[1]->setAttribute($attr['name'], $attr['value']);
2260 if ($this->elementInScope('p')) {
2261 $this->emitToken(
2270 $this->insertElement($token);
2277 if ($this->form_pointer !== null) {
2285 if ($this->elementInScope('p')) {
2286 $this->emitToken(
2296 $element = $this->insertElement($token);
2297 $this->form_pointer = $element;
2308 if ($this->elementInScope('p')) {
2309 $this->emitToken(
2317 $stack_length = count($this->stack) - 1;
2323 $node = $this->stack[$n];
2324 $cat = $this->getElementCategory($node->tagName);
2333 array_pop($this->stack);
2351 $this->insertElement($token);
2359 if ($this->elementInScope('p')) {
2360 $this->emitToken(
2369 $this->insertElement($token);
2384 if ($this->elementInScope('p')) {
2385 $this->emitToken(
2398 while ($this->elementInScope(array('h1', 'h2', 'h3', 'h4', 'h5', 'h6'))) {
2399 array_pop($this->stack);
2403 $this->insertElement($token);
2417 $leng = count($this->a_formatting);
2420 if ($this->a_formatting[$n] === self::MARKER) {
2423 } elseif ($this->a_formatting[$n]->nodeName === 'a') {
2424 $this->emitToken(
2435 $this->reconstructActiveFormattingElements();
2438 $el = $this->insertElement($token);
2442 $this->a_formatting[] = $el;
2460 $this->reconstructActiveFormattingElements();
2463 $el = $this->insertElement($token);
2467 $this->a_formatting[] = $el;
2476 if ($this->elementInScope('button')) {
2477 $this->inBody(
2486 $this->reconstructActiveFormattingElements();
2489 $this->insertElement($token);
2493 $this->a_formatting[] = self::MARKER;
2500 $this->reconstructActiveFormattingElements();
2503 $this->insertElement($token);
2507 $this->a_formatting[] = self::MARKER;
2513 $this->reconstructActiveFormattingElements();
2516 $this->insertElement($token);
2526 if ($this->elementInScope('p')) {
2527 $this->emitToken(
2536 $this->insertElement($token);
2539 $this->mode = self::IN_TABLE;
2554 $this->reconstructActiveFormattingElements();
2557 $this->insertElement($token);
2560 array_pop($this->stack);
2567 if ($this->elementInScope('p')) {
2568 $this->emitToken(
2577 $this->insertElement($token);
2580 array_pop($this->stack);
2588 return $this->inBody($token);
2594 $this->reconstructActiveFormattingElements();
2597 $element = $this->insertElement($token, false);
2602 $this->form_pointer !== null
2603 ? $this->form_pointer->appendChild($element)
2604 : end($this->stack)->appendChild($element);
2607 array_pop($this->stack);
2617 if ($this->form_pointer === null) {
2620 $this->inBody(
2630 $this->inBody(
2640 $this->inBody(
2650 $this->inBody(
2659 $this->insertText(
2671 $this->inBody(
2681 $this->insertText(
2688 $this->inBody(
2697 $this->inBody(
2706 $this->inBody(
2715 $this->inBody(
2726 $this->insertElement($token);
2738 $this->insertElement($token);
2747 $this->reconstructActiveFormattingElements();
2750 $this->insertElement($token);
2753 $this->mode = self::IN_SELECT;
2794 $this->reconstructActiveFormattingElements();
2796 $this->insertElement($token, true, true);
2808 if (count($this->stack) < 2 || $this->stack[1]->nodeName !== 'body') {
2813 } elseif (end($this->stack)->nodeName !== 'body') {
2818 $this->mode = self::AFTER_BODY;
2826 $this->inBody(
2833 return $this->afterBody($token);
2854 if ($this->elementInScope($token['name'])) {
2855 $this->generateImpliedEndTags();
2866 for ($n = count($this->stack) - 1; $n >= 0; $n--) {
2867 if ($this->stack[$n]->nodeName === $token['name']) {
2871 array_pop($this->stack);
2881 if ($this->elementInScope($token['name'])) {
2882 $this->generateImpliedEndTags();
2886 if (end($this->stack)->nodeName !== $token['name']) {
2896 array_pop($this->stack);
2900 $this->form_pointer = null;
2907 if ($this->elementInScope('p')) {
2908 $this->generateImpliedEndTags(array('p'));
2917 for ($n = count($this->stack) - 1; $n >= 0; $n--) {
2918 if ($this->elementInScope('p')) {
2919 array_pop($this->stack);
2936 if ($this->elementInScope($token['name'])) {
2937 $this->generateImpliedEndTags(array($token['name']));
2947 for ($n = count($this->stack) - 1; $n >= 0; $n--) {
2948 if ($this->stack[$n]->nodeName === $token['name']) {
2952 array_pop($this->stack);
2970 if ($this->elementInScope($elements)) {
2971 $this->generateImpliedEndTags();
2981 while ($this->elementInScope($elements)) {
2982 array_pop($this->stack);
3010 for ($a = count($this->a_formatting) - 1; $a >= 0; $a--) {
3011 if ($this->a_formatting[$a] === self::MARKER) {
3014 } elseif ($this->a_formatting[$a]->tagName === $token['name']) {
3015 $formatting_element = $this->a_formatting[$a];
3016 $in_stack = in_array($formatting_element, $this->stack, true);
3027 !$this->elementInScope($token['name']))
3036 unset($this->a_formatting[$fe_af_pos]);
3037 $this->a_formatting = array_merge($this->a_formatting);
3046 $fe_s_pos = array_search($formatting_element, $this->stack, true);
3047 $length = count($this->stack);
3050 $category = $this->getElementCategory($this->stack[$s]->nodeName);
3053 $furthest_block = $this->stack[$s];
3065 array_pop($this->stack);
3068 unset($this->a_formatting[$fe_af_pos]);
3069 $this->a_formatting = array_merge($this->a_formatting);
3076 $common_ancestor = $this->stack[$fe_s_pos - 1];
3096 … for ($n = array_search($node, $this->stack, true) - 1; $n >= 0; $n--) {
3099 $node = $this->stack[$n];
3105 if (!in_array($node, $this->a_formatting, true)) {
3106 unset($this->stack[$n]);
3107 $this->stack = array_merge($this->stack);
3125 $bookmark = array_search($node, $this->a_formatting, true) + 1;
3136 $s_pos = array_search($node, $this->stack, true);
3137 $a_pos = array_search($node, $this->a_formatting, true);
3139 $this->stack[$s_pos] = $clone;
3140 $this->a_formatting[$a_pos] = $clone;
3186 … $fe_af_pos = array_search($formatting_element, $this->a_formatting, true);
3187 unset($this->a_formatting[$fe_af_pos]);
3188 $this->a_formatting = array_merge($this->a_formatting);
3190 $af_part1 = array_slice($this->a_formatting, 0, $bookmark - 1);
3191 … $af_part2 = array_slice($this->a_formatting, $bookmark, count($this->a_formatting));
3192 $this->a_formatting = array_merge($af_part1, array($clone), $af_part2);
3199 $fe_s_pos = array_search($formatting_element, $this->stack, true);
3200 $fb_s_pos = array_search($furthest_block, $this->stack, true);
3201 unset($this->stack[$fe_s_pos]);
3203 $s_part1 = array_slice($this->stack, 0, $fb_s_pos);
3204 … $s_part2 = array_slice($this->stack, $fb_s_pos + 1, count($this->stack));
3205 $this->stack = array_merge($s_part1, array($clone), $s_part2);
3220 if ($this->elementInScope($token['name'])) {
3221 $this->generateImpliedEndTags();
3232 for ($n = count($this->stack) - 1; $n >= 0; $n--) {
3233 if ($this->stack[$n]->nodeName === $token['name']) {
3237 array_pop($this->stack);
3240 $marker = end(array_keys($this->a_formatting, self::MARKER, true));
3242 for ($n = count($this->a_formatting) - 1; $n > $marker; $n--) {
3243 array_pop($this->a_formatting);
3276 for ($n = count($this->stack) - 1; $n >= 0; $n--) {
3279 $node = end($this->stack);
3285 $this->generateImpliedEndTags();
3294 for ($x = count($this->stack) - $n; $x >= $n; $x--) {
3295 array_pop($this->stack);
3299 $category = $this->getElementCategory($node);
3327 $text = $this->dom->createTextNode($token['data']);
3328 end($this->stack)->appendChild($text);
3334 $comment = $this->dom->createComment($token['data']);
3335 end($this->stack)->appendChild($comment);
3342 $this->clearStackToTableContext($clear);
3346 $this->a_formatting[] = self::MARKER;
3350 $this->insertElement($token);
3351 $this->mode = self::IN_CAPTION;
3358 $this->clearStackToTableContext($clear);
3362 $this->insertElement($token);
3363 $this->mode = self::IN_CGROUP;
3369 $this->inTable(
3377 $this->inColumnGroup($token);
3386 $this->clearStackToTableContext($clear);
3390 $this->insertElement($token);
3391 $this->mode = self::IN_TBODY;
3399 $this->inTable(
3407 return $this->inTableBody($token);
3416 $this->inTable(
3423 return $this->mainPhase($token);
3432 if (!$this->elementInScope($token['name'], true)) {
3438 $this->generateImpliedEndTags();
3447 $current = end($this->stack)->nodeName;
3448 array_pop($this->stack);
3456 $this->resetInsertionMode();
3489 end($this->stack)->nodeName,
3504 for ($n = count($this->stack) - 1; $n >= 0; $n--) {
3505 if ($this->stack[$n]->nodeName === 'table') {
3506 $table = $this->stack[$n];
3512 $this->foster_parent = $table->parentNode;
3515 $this->foster_parent = $this->stack[0];
3520 $this->foster_parent = $this->stack[$n - 1];
3524 $this->inBody($token);
3535 if (!$this->elementInScope($token['name'], true)) {
3541 $this->generateImpliedEndTags();
3550 $node = end($this->stack)->nodeName;
3551 array_pop($this->stack);
3560 $this->clearTheActiveFormattingElementsUpToTheLastMarker();
3563 $this->mode = self::IN_TABLE;
3588 $this->inCaption(
3595 return $this->inTable($token);
3619 $this->inBody($token);
3632 $text = $this->dom->createTextNode($token['data']);
3633 end($this->stack)->appendChild($text);
3639 $comment = $this->dom->createComment($token['data']);
3640 end($this->stack)->appendChild($comment);
3646 $this->insertElement($token);
3647 array_pop($this->stack);
3655 if (end($this->stack)->nodeName === 'html') {
3662 array_pop($this->stack);
3663 $this->mode = self::IN_TABLE;
3674 $this->inColumnGroup(
3681 return $this->inTable($token);
3692 $this->clearStackToTableContext($clear);
3696 $this->insertElement($token);
3697 $this->mode = self::IN_ROW;
3705 $this->inTableBody(
3713 return $this->inRow($token);
3722 if (!$this->elementInScope($token['name'], true)) {
3728 $this->clearStackToTableContext($clear);
3732 array_pop($this->stack);
3733 $this->mode = self::IN_TABLE;
3747 if (!$this->elementInScope(array('tbody', 'thead', 'tfoot'), true)) {
3753 $this->clearStackToTableContext($clear);
3758 $this->inTableBody(
3760 'name' => end($this->stack)->nodeName,
3765 return $this->mainPhase($token);
3780 $this->inTable($token);
3793 $this->clearStackToTableContext($clear);
3797 $this->insertElement($token);
3798 $this->mode = self::IN_CELL;
3802 $this->a_formatting[] = self::MARKER;
3809 if (!$this->elementInScope($token['name'], true)) {
3815 $this->clearStackToTableContext($clear);
3820 array_pop($this->stack);
3821 $this->mode = self::IN_TBODY;
3833 $this->inRow(
3840 return $this->inCell($token);
3849 if (!$this->elementInScope($token['name'], true)) {
3856 $this->inRow(
3863 return $this->inCell($token);
3878 $this->inTable($token);
3891 if (!$this->elementInScope($token['name'], true)) {
3898 $this->generateImpliedEndTags(array($token['name']));
3907 $node = end($this->stack)->nodeName;
3908 array_pop($this->stack);
3917 $this->clearTheActiveFormattingElementsUpToTheLastMarker();
3921 $this->mode = self::IN_ROW;
3944 if (!$this->elementInScope(array('td', 'th'), true)) {
3950 $this->closeCell();
3951 return $this->inRow($token);
3974 if (!$this->elementInScope(array('td', 'th'), true)) {
3980 $this->closeCell();
3981 return $this->inRow($token);
4004 if (!$this->elementInScope($token['name'], true)) {
4010 $this->closeCell();
4011 return $this->inRow($token);
4017 $this->inBody($token);
4028 $this->insertText($token['data']);
4034 $this->insertComment($token['data']);
4042 if (end($this->stack)->nodeName === 'option') {
4043 $this->inSelect(
4052 $this->insertElement($token);
4060 if (end($this->stack)->nodeName === 'option') {
4061 $this->inSelect(
4071 if (end($this->stack)->nodeName === 'optgroup') {
4072 $this->inSelect(
4081 $this->insertElement($token);
4091 $elements_in_stack = count($this->stack);
4093 if ($this->stack[$elements_in_stack - 1]->nodeName === 'option' &&
4094 $this->stack[$elements_in_stack - 2]->nodeName === 'optgroup'
4096 $this->inSelect(
4107 if ($this->stack[$elements_in_stack - 1] === 'optgroup') {
4108 array_pop($this->stack);
4118 if (end($this->stack)->nodeName === 'option') {
4119 array_pop($this->stack);
4129 if (!$this->elementInScope($token['name'], true)) {
4137 $current = end($this->stack)->nodeName;
4138 array_pop($this->stack);
4146 $this->resetInsertionMode();
4155 $this->inSelect(
4185 if ($this->elementInScope($token['name'], true)) {
4186 $this->inSelect(
4193 $this->mainPhase($token);
4214 $this->inBody($token);
4221 $comment = $this->dom->createComment($token['data']);
4222 $this->stack[0]->appendChild($comment);
4232 $this->phase = self::END_PHASE;
4238 $this->mode = self::IN_BODY;
4239 return $this->inBody($token);
4254 $this->insertText($token['data']);
4260 $this->insertComment($token['data']);
4266 $this->insertElement($token);
4274 if (end($this->stack)->nodeName === 'html') {
4280 array_pop($this->stack);
4286 $this->mode = self::AFTR_FRAME;
4294 $this->insertElement($token);
4297 array_pop($this->stack);
4304 $this->inBody($token);
4323 $this->insertText($token['data']);
4329 $this->insertComment($token['data']);
4336 $this->phase = self::END_PHASE;
4343 $this->inBody($token);
4364 $comment = $this->dom->createComment($token['data']);
4365 $this->dom->appendChild($comment);
4374 $this->mainPhase($token);
4385 $this->phase = self::MAIN_PHASE;
4386 return $this->mainPhase($token);
4409 $el = $this->dom->createElement($token['name']);
4417 $this->appendToRealParent($el);
4418 $this->stack[] = $el;
4425 $text = $this->dom->createTextNode($data);
4426 $this->appendToRealParent($text);
4431 $comment = $this->dom->createComment($data);
4432 $this->appendToRealParent($comment);
4437 if ($this->foster_parent === null) {
4438 end($this->stack)->appendChild($node);
4440 } elseif ($this->foster_parent !== null) {
4447 for ($n = count($this->stack) - 1; $n >= 0; $n--) {
4448 if ($this->stack[$n]->nodeName === 'table' &&
4449 $this->stack[$n]->parentNode !== null
4451 $table = $this->stack[$n];
4456 if (isset($table) && $this->foster_parent->isSameNode($table->parentNode)) {
4457 $this->foster_parent->insertBefore($node, $table);
4459 $this->foster_parent->appendChild($node);
4462 $this->foster_parent = null;
4470 if ($this->elementInScope($element, $table)) {
4478 $leng = count($this->stack);
4483 $node = $this->stack[$leng - 1 - $n];
4530 $formatting_elements = count($this->a_formatting);
4538 $entry = end($this->a_formatting);
4544 if ($entry === self::MARKER || in_array($entry, $this->stack, true)) {
4559 $entry = $this->a_formatting[$a];
4563 if ($entry === self::MARKER || in_array($entry, $this->stack, true)) {
4573 $entry = $this->a_formatting[$a];
4581 end($this->stack)->appendChild($clone);
4582 $this->stack[] = $clone;
4586 $this->a_formatting[$a] = $clone;
4590 if (end($this->a_formatting) !== $clone) {
4607 $entry = end($this->a_formatting);
4610 array_pop($this->a_formatting);
4627 $node = end($this->stack);
4630 while (in_array(end($this->stack)->nodeName, $elements)) {
4631 array_pop($this->stack);
4638 if (in_array($name, $this->special)) {
4640 } elseif (in_array($name, $this->scoping)) {
4642 } elseif (in_array($name, $this->formatting)) {
4657 $node = end($this->stack)->nodeName;
4662 array_pop($this->stack);
4671 $leng = count($this->stack);
4675 $node = $this->stack[$n];
4681 if ($this->stack[0]->isSameNode($node)) {
4688 $this->mode = self::IN_SELECT;
4694 $this->mode = self::IN_CELL;
4700 $this->mode = self::IN_ROW;
4706 $this->mode = self::IN_TBODY;
4712 $this->mode = self::IN_CAPTION;
4718 $this->mode = self::IN_CGROUP;
4724 $this->mode = self::IN_TABLE;
4731 $this->mode = self::IN_BODY;
4737 $this->mode = self::IN_BODY;
4743 $this->mode = self::IN_FRAME;
4751 $this->mode = ($this->head_pointer === null)
4760 $this->mode = self::IN_BODY;
4771 if ($this->elementInScope($cell, true)) {
4772 $this->inCell(
4786 return $this->dom;