# A start tag whose tag name is one of: "th", "td"
# Clear the stack back to a table row context. (See below.)
# Insert an HTML element for the token, then switch the insertion mode to "in cell".
# Insert a marker at the end of the list of active formatting elements.
# An end tag whose tag name is "tr"
# If the stack of open elements does not have a tr element in table scope, this is a parse error; ignore the token.
# Otherwise:
# Clear the stack back to a table row context. (See below.)
# Pop the current node (which will be a tr element) from the stack of open elements. Switch the insertion mode to "in table body".
# A start tag whose tag name is one of: "caption", "col", "colgroup", "tbody", "tfoot", "thead", "tr"
# An end tag whose tag name is "table"
# If the stack of open elements does not have a tr element in table scope, this is a parse error; ignore the token.
# Otherwise:
# Clear the stack back to a table row context. (See below.)
# Pop the current node (which will be a tr element) from the stack of open elements. Switch the insertion mode to "in table body".
# Reprocess the token.
# An end tag whose tag name is one of: "tbody", "tfoot", "thead"
# If the stack of open elements does not have an element in table scope that is an HTML element with the same tag name as the token, this is a parse error; ignore the token.
# If the stack of open elements does not have a tr element in table scope, ignore the token.
# Otherwise:
# Clear the stack back to a table row context. (See below.)
# Pop the current node (which will be a tr element) from the stack of open elements. Switch the insertion mode to "in table body".
# Reprocess the token.
# An end tag whose tag name is one of: "body", "caption", "col", "colgroup", "html", "td", "th"
# Parse error. Ignore the token.
# Anything else
# Process the token using the rules for the "in table" insertion mode.
# 13.2.6.4.15 The "in cell" insertion mode
# An end tag whose tag name is one of: "td", "th"
# If the stack of open elements does not have an element in table scope that is an HTML element with the same tag name as that of the token, then this is a parse error; ignore the token.
# Otherwise:
# Generate implied end tags.
# Now, if the current node is not an HTML element with the same tag name as the token, then this is a parse error.
# Pop elements from the stack of open elements stack until an HTML element with the same tag name as the token has been popped from the stack.
# Clear the list of active formatting elements up to the last marker.
# Switch the insertion mode to "in row".
# A start tag whose tag name is one of: "caption", "col", "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"
# If the stack of open elements does not have a td or th element in table scope, then this is a parse error; ignore the token. (fragment case)
# Otherwise, close the cell (see below) and reprocess the token.
# An end tag whose tag name is one of: "body", "caption", "col", "colgroup", "html"
# Parse error. Ignore the token.
# An end tag whose tag name is one of: "table", "tbody", "tfoot", "thead", "tr"
# If the stack of open elements does not have an element in table scope that is an HTML element with the same tag name as that of the token, then this is a parse error; ignore the token.
# Otherwise, close the cell (see below) and reprocess the token.
# Anything else
# Process the token using the rules for the "in body" insertion mode.
# Where the steps above say to close the cell, they mean to run the following algorithm:
# Generate implied end tags.
# If the current node is not now a td element or a th element, then this is a parse error.
# Pop elements from the stack of open elements stack until a td element or a th element has been popped from the stack.
# Clear the list of active formatting elements up to the last marker.
# Switch the insertion mode to "in row".
# 13.2.6.4.16 The "in select" insertion mode
# A character token that is U+0000 NULL
# Parse error. Ignore the token.
# Any other character token
# Insert the token's character.
# A comment token
# Insert a comment.
# A DOCTYPE token
# Parse error. Ignore the token.
# A start tag whose tag name is "html"
# Process the token using the rules for the "in body" insertion mode.
# A start tag whose tag name is "option"
# If the current node is an option element, pop that node from the stack of open elements.
# Insert an HTML element for the token.
# A start tag whose tag name is "optgroup"
# If the current node is an option element, pop that node from the stack of open elements.
# If the current node is an optgroup element, pop that node from the stack of open elements.
# Insert an HTML element for the token.
# An end tag whose tag name is "optgroup"
# First, if the current node is an option element, and the node immediately before it in the stack of open elements is an optgroup element, then pop the current node from the stack of open elements.
# If the current node is an optgroup element, then pop that node from the stack of open elements. Otherwise, this is a parse error; ignore the token.
# An end tag whose tag name is "option"
# If the current node is an option element, then pop that node from the stack of open elements. Otherwise, this is a parse error; ignore the token.
# An end tag whose tag name is "select"
# If the stack of open elements does not have a select element in select scope, this is a parse error; ignore the token. (fragment case)
# Otherwise:
# Pop elements from the stack of open elements until a select element has been popped from the stack.
# Reset the insertion mode appropriately.
# A start tag whose tag name is "select"
# Parse error.
# If the stack of open elements does not have a select element in select scope, ignore the token. (fragment case)
# Otherwise:
# Pop elements from the stack of open elements until a select element has been popped from the stack.
# Reset the insertion mode appropriately.
# It just gets treated like an end tag.
# A start tag whose tag name is one of: "input", "keygen", "textarea"
# Parse error.
# If the stack of open elements does not have a select element in select scope, ignore the token. (fragment case)
# Otherwise:
# Pop elements from the stack of open elements until a select element has been popped from the stack.
# Reset the insertion mode appropriately.
# Reprocess the token.
# A start tag whose tag name is one of: "script", "template"
# An end tag whose tag name is "template"
# Process the token using the rules for the "in head" insertion mode.
# An end-of-file token
# Process the token using the rules for the "in body" insertion mode.
# Anything else
# Parse error. Ignore the token.
# 13.2.6.4.17 The "in select in table" insertion mode
# A start tag whose tag name is one of: "caption", "table", "tbody", "tfoot", "thead", "tr", "td", "th"
# Parse error.
# Pop elements from the stack of open elements until a select element has been popped from the stack.
# Reset the insertion mode appropriately.
# Reprocess the token.
# An end tag whose tag name is one of: "caption", "table", "tbody", "tfoot", "thead", "tr", "td", "th"
# Parse error.
# If the stack of open elements does not have an element in table scope that is an HTML element with the same tag name as that of the token, then ignore the token.
# Otherwise:
# Pop elements from the stack of open elements until a select element has been popped from the stack.
# Reset the insertion mode appropriately.
# Reprocess the token.
# Anything else
# Process the token using the rules for the "in select" insertion mode.
# 13.2.6.4.18 The "in template" insertion mode
# A character token
# A comment token
# A DOCTYPE token
# Process the token using the rules for the "in body" insertion mode.
# A start tag whose tag name is one of: "base", "basefont", "bgsound", "link", "meta", "noframes", "script", "style", "template", "title"
# An end tag whose tag name is "template"
# Process the token using the rules for the "in head" insertion mode.
# A start tag whose tag name is one of: "caption", "colgroup", "tbody", "tfoot", "thead"
# Pop the current template insertion mode off the stack of template insertion modes.
# Push "in table" onto the stack of template insertion modes so that it is the new current template insertion mode.
# Switch the insertion mode to "in table", and reprocess the token.
# A start tag whose tag name is "col"
# Pop the current template insertion mode off the stack of template insertion modes.
# Push "in column group" onto the stack of template insertion modes so that it is the new current template insertion mode.
# Switch the insertion mode to "in column group", and reprocess the token.
# A start tag whose tag name is "tr"
# Pop the current template insertion mode off the stack of template insertion modes.
# Push "in table body" onto the stack of template insertion modes so that it is the new current template insertion mode.
# Switch the insertion mode to "in table body", and reprocess the token.
# A start tag whose tag name is one of: "td", "th"
# Pop the current template insertion mode off the stack of template insertion modes.
# Push "in row" onto the stack of template insertion modes so that it is the new current template insertion mode.
# Switch the insertion mode to "in row", and reprocess the token.
# Any other start tag
# Pop the current template insertion mode off the stack of template insertion modes.
# Push "in body" onto the stack of template insertion modes so that it is the new current template insertion mode.
# Switch the insertion mode to "in body", and reprocess the token.
# Any other end tag
# Parse error. Ignore the token.
# An end-of-file token
# If there is no template element on the stack of open elements, then stop parsing. (fragment case)
# Otherwise, this is a parse error.
# Pop elements from the stack of open elements until a template element has been popped from the stack.
# Clear the list of active formatting elements up to the last marker.
# Pop the current template insertion mode off the stack of template insertion modes.
# Reset the insertion mode appropriately.
# Reprocess the token.
# 13.2.6.4.19 The "after body" insertion mode
# A character token that is one of U+0009 CHARACTER TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF), U+000D CARRIAGE RETURN (CR), or U+0020 SPACE
# Process the token using the rules for the "in body" insertion mode.
# A comment token
# Insert a comment as the last child of the first element in the stack of open elements (the html element).
# A DOCTYPE token
# Parse error. Ignore the token.
# A start tag whose tag name is "html"
# Process the token using the rules for the "in body" insertion mode.
# An end tag whose tag name is "html"
# If the parser was created as part of the HTML fragment parsing algorithm, this is a parse error; ignore the token. (fragment case)
# Otherwise, switch the insertion mode to "after after body".
# An end-of-file token
# Stop parsing.
# Anything else
# Parse error. Switch the insertion mode to "in body" and reprocess the token.
# 13.2.6.4.20 The "in frameset" insertion mode
# A character token that is one of U+0009 CHARACTER TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF), U+000D CARRIAGE RETURN (CR), or U+0020 SPACE
# Insert the character.
# A comment token
# Insert a comment.
# A DOCTYPE token
# Parse error. Ignore the token.
# A start tag whose tag name is "html"
# Process the token using the rules for the "in body" insertion mode.
# A start tag whose tag name is "frameset"
# Insert an HTML element for the token.
# An end tag whose tag name is "frameset"
# If the current node is the root html element, then this is a parse error; ignore the token. (fragment case)
# Otherwise, pop the current node from the stack of open elements.
# If the parser was not created as part of the HTML fragment parsing algorithm (fragment case), and the current node is no longer a frameset element, then switch the insertion mode to "after frameset".
# A start tag whose tag name is "frame"
# Insert an HTML element for the token. Immediately pop the current node off the stack of open elements.
# Acknowledge the token's self-closing flag, if it is set.
# A start tag whose tag name is "noframes"
# Process the token using the rules for the "in head" insertion mode.
# An end-of-file token
# If the current node is not the root html element, then this is a parse error.
# The current node can only be the root html element in the fragment case.
# Stop parsing.
# Anything else
# Parse error. Ignore the token.
# 13.2.6.4.21 The "after frameset" insertion mode
# A character token that is one of U+0009 CHARACTER TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF), U+000D CARRIAGE RETURN (CR), or U+0020 SPACE
# Insert the character.
# A comment token
# Insert a comment.
# A DOCTYPE token
# Parse error. Ignore the token.
# A start tag whose tag name is "html"
# Process the token using the rules for the "in body" insertion mode.
# An end tag whose tag name is "html"
# Switch the insertion mode to "after after frameset".
# A start tag whose tag name is "noframes"
# Process the token using the rules for the "in head" insertion mode.
# An end-of-file token
# Stop parsing.
# Anything else
# Parse error. Ignore the token.
# 13.2.6.4.22 The "after after body" insertion mode
# A comment token
# Insert a comment as the last child of the Document object.
# A DOCTYPE token
# A character token that is one of U+0009 CHARACTER TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF), U+000D CARRIAGE RETURN (CR), or U+0020 SPACE
# A start tag whose tag name is "html"
# Process the token using the rules for the "in body" insertion mode.
# An end-of-file token
# Stop parsing.
# Anything else
# Parse error. Switch the insertion mode to "in body" and reprocess the token.
# 13.2.6.4.23 The "after after frameset" insertion mode
# A comment token
# Insert a comment as the last child of the Document object.
# A DOCTYPE token
# A character token that is one of U+0009 CHARACTER TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF), U+000D CARRIAGE RETURN (CR), or U+0020 SPACE
# A start tag whose tag name is "html"
# Process the token using the rules for the "in body" insertion mode.
# An end-of-file token
# Stop parsing.
# A start tag whose tag name is "noframes"
# Process the token using the rules for the "in head" insertion mode.
# Anything else
# Parse error. Ignore the token.
else {
throw new NotImplementedException("NOT IMPLEMENTED");
}
@ -2345,7 +3124,6 @@ class TreeBuilder {
protected function appropriatePlaceForInsertingNode(\DOMNode $overrideTarget = null): array {
$insertBefore = false;
# 13.2.6.1. Creating and inserting nodes
#
# While the parser is processing a token, it can enable or disable foster
@ -2368,24 +3146,21 @@ class TreeBuilder {
#
# 1. Let last template be the last template element in the stack of open