src/Parser/HTML/ParserOrTreeBuilder.php
/**
     * Resets the HTML Parser's insertion mode.
     *
     * @see https://html.spec.whatwg.org/multipage/syntax.html#reset-the-insertion-mode-appropriately
     */
Resets the HTML Parser's insertion mode.
Resets the HTML Parser ' s insertion mode .
public function resetInsertionMode(): void
    {
        $last = false;
        $iterator = $this->openElements->getIterator();
        foreach ($iterator as $node) {
            if ($this->openElements->top() === $node) {
                $last = true;
                if ($this->isFragmentCase) {
                    $node = $this->contextElement;
                }
            }
            if ($node instanceof HTMLSelectElement) {
                if (!$last) {
                    $ancestor = $node;
                    while ($iterator->valid()) {
                        if ($ancestor === $this->openElements->top()) {
                            break;
                        }
                        $iterator->next();
                        $ancestor = $iterator->current();
                        if ($ancestor instanceof HTMLTemplateElement) {
                            break;
                        }
                        if ($ancestor instanceof HTMLTableElement) {
                            $this->state->insertionMode = ParserInsertionMode::IN_SELECT_IN_TABLE;
                            break 2;
                        }
                    }
                }
                $this->state->insertionMode = ParserInsertionMode::IN_SELECT;
                break;
            } elseif ($node instanceof HTMLTableCellElement && !$last) {
                $this->state->insertionMode = ParserInsertionMode::IN_CELL;
                break;
            } elseif ($node instanceof HTMLTableRowElement) {
                $this->state->insertionMode = ParserInsertionMode::IN_ROW;
                break;
            } elseif ($node instanceof HTMLTableSectionElement) {
                $this->state->insertionMode = ParserInsertionMode::IN_TABLE_BODY;
                break;
            } elseif ($node instanceof HTMLTableCaptionElement) {
                $this->state->insertionMode = ParserInsertionMode::IN_CAPTION;
                break;
            } elseif ($node instanceof HTMLTableColElement && $node->localName === 'colgroup') {
                $this->state->insertionMode = ParserInsertionMode::IN_COLUMN_GROUP;
                break;
            } elseif ($node instanceof HTMLTableElement) {
                $this->state->insertionMode = ParserInsertionMode::IN_TABLE;
                break;
            } elseif ($node instanceof HTMLTemplateElement) {
                $this->state->insertionMode = $this->templateInsertionModes->top();
                break;
            } elseif ($node instanceof HTMLHeadElement && !$last) {
                $this->state->insertionMode = ParserInsertionMode::IN_HEAD;
                break;
            } elseif ($node instanceof HTMLBodyElement) {
                $this->state->insertionMode = ParserInsertionMode::IN_BODY;
                break;
            } elseif ($node instanceof HTMLFrameSetElement) {
                $this->state->insertionMode = ParserInsertionMode::IN_FRAMESET;
                break;
            } elseif ($node instanceof HTMLHtmlElement) {
                if (!$this->state->headElementPointer) {
                    $this->state->insertionMode = ParserInsertionMode::BEFORE_HEAD;
                } else {
                    $this->state->insertionMode = ParserInsertionMode::AFTER_HEAD;
                }
                break;
            } elseif ($last) {
                $this->state->insertionMode = ParserInsertionMode::IN_BODY;
            }
        }
    }
public function resetInsertionMode ( ) : void { $ last = false ; $ iterator = $ this -> openElements -> getIterator ( ) ; foreach ( $ iterator as $ node ) { if ( $ this -> openElements -> top ( ) === $ node ) { $ last = true ; if ( $ this -> isFragmentCase ) { $ node = $ this -> contextElement ; } } if ( $ node instanceof HTMLSelectElement ) { if ( ! $ last ) { $ ancestor = $ node ; while ( $ iterator -> valid ( ) ) { if ( $ ancestor === $ this -> openElements -> top ( ) ) { break ; } $ iterator -> next ( ) ; $ ancestor = $ iterator -> current ( ) ; if ( $ ancestor instanceof HTMLTemplateElement ) { break ; } if ( $ ancestor instanceof HTMLTableElement ) { $ this -> state -> insertionMode = ParserInsertionMode :: IN_SELECT_IN_TABLE ; break 2 ; } } } $ this -> state -> insertionMode = ParserInsertionMode :: IN_SELECT ; break ; } elseif ( $ node instanceof HTMLTableCellElement && ! $ last ) { $ this -> state -> insertionMode = ParserInsertionMode :: IN_CELL ; break ; } elseif ( $ node instanceof HTMLTableRowElement ) { $ this -> state -> insertionMode = ParserInsertionMode :: IN_ROW ; break ; } elseif ( $ node instanceof HTMLTableSectionElement ) { $ this -> state -> insertionMode = ParserInsertionMode :: IN_TABLE_BODY ; break ; } elseif ( $ node instanceof HTMLTableCaptionElement ) { $ this -> state -> insertionMode = ParserInsertionMode :: IN_CAPTION ; break ; } elseif ( $ node instanceof HTMLTableColElement && $ node -> localName === 'colgroup' ) { $ this -> state -> insertionMode = ParserInsertionMode :: IN_COLUMN_GROUP ; break ; } elseif ( $ node instanceof HTMLTableElement ) { $ this -> state -> insertionMode = ParserInsertionMode :: IN_TABLE ; break ; } elseif ( $ node instanceof HTMLTemplateElement ) { $ this -> state -> insertionMode = $ this -> templateInsertionModes -> top ( ) ; break ; } elseif ( $ node instanceof HTMLHeadElement && ! $ last ) { $ this -> state -> insertionMode = ParserInsertionMode :: IN_HEAD ; break ; } elseif ( $ node instanceof HTMLBodyElement ) { $ this -> state -> insertionMode = ParserInsertionMode :: IN_BODY ; break ; } elseif ( $ node instanceof HTMLFrameSetElement ) { $ this -> state -> insertionMode = ParserInsertionMode :: IN_FRAMESET ; break ; } elseif ( $ node instanceof HTMLHtmlElement ) { if ( ! $ this -> state -> headElementPointer ) { $ this -> state -> insertionMode = ParserInsertionMode :: BEFORE_HEAD ; } else { $ this -> state -> insertionMode = ParserInsertionMode :: AFTER_HEAD ; } break ; } elseif ( $ last ) { $ this -> state -> insertionMode = ParserInsertionMode :: IN_BODY ; } } }
Resets the HTML Parser's insertion mode.
Resets the HTML Parser ' s insertion mode .
// Fragment case // Fragment case // Fragment case // Fragment case