Parses next element in the ‘in table’ insertion mode.
Description
This internal function performs the ‘in table’ insertion mode logic for the generalized WP_HTML_Processor::step() function.
See also
Source
* > 3. Pop elements from the stack of open elements until a select element
* > has been popped from the stack.
*/
if ( $this->state->stack_of_open_elements->has_element_in_scope( 'SELECT' ) ) {
// @todo Indicate a parse error once it's possible.
$this->state->stack_of_open_elements->pop_until( 'SELECT' );
return $this->step();
}
$this->reconstruct_active_formatting_elements();
$this->insert_html_element( $this->state->current_token );
$this->state->frameset_ok = false;
return true;
/*
* > A start tag whose tag name is "option"
*/
case '+OPTION':
if ( $this->state->stack_of_open_elements->has_element_in_scope( 'SELECT' ) ) {
$this->generate_implied_end_tags( 'OPTGROUP' );
/*
* > If the stack of open elements has an option element in scope, then this
* > is a parse error.
* @todo Indicate a parse error once it's possible.
*/
} elseif ( $this->state->stack_of_open_elements->current_node_is( 'OPTION' ) ) {
$this->state->stack_of_open_elements->pop();
}
$this->reconstruct_active_formatting_elements();
$this->insert_html_element( $this->state->current_token );
return true;
/*
* > A start tag whose tag name is "optgroup"
*/
case '+OPTGROUP':
if ( $this->state->stack_of_open_elements->has_element_in_scope( 'SELECT' ) ) {
$this->generate_implied_end_tags();
/*
* > If the stack of open elements has an option element in scope or has an
* > optgroup element in scope, then this is a parse error.
* @todo Indicate a parse error once it's possible.
*/
} elseif ( $this->state->stack_of_open_elements->current_node_is( 'OPTION' ) ) {
$this->state->stack_of_open_elements->pop();
}
$this->reconstruct_active_formatting_elements();
$this->insert_html_element( $this->state->current_token );
return true;
/*
* > A start tag whose tag name is one of: "rb", "rtc"
*/
case '+RB':
case '+RTC':
if ( $this->state->stack_of_open_elements->has_element_in_scope( 'RUBY' ) ) {
$this->generate_implied_end_tags();
if ( $this->state->stack_of_open_elements->current_node_is( 'RUBY' ) ) {
// @todo Indicate a parse error once it's possible.
}
}
$this->insert_html_element( $this->state->current_token );
return true;
/*
* > A start tag whose tag name is one of: "rp", "rt"
*/
case '+RP':
case '+RT':
if ( $this->state->stack_of_open_elements->has_element_in_scope( 'RUBY' ) ) {
$this->generate_implied_end_tags( 'RTC' );
$current_node_name = $this->state->stack_of_open_elements->current_node()->node_name;
if ( 'RTC' === $current_node_name || 'RUBY' === $current_node_name ) {
// @todo Indicate a parse error once it's possible.
}
}
$this->insert_html_element( $this->state->current_token );
return true;
/*
* > A start tag whose tag name is "math"
*/
case '+MATH':
$this->reconstruct_active_formatting_elements();
/*
* @todo Adjust MathML attributes for the token. (This fixes the case of MathML attributes that are not all lowercase.)
* @todo Adjust foreign attributes for the token. (This fixes the use of namespaced attributes, in particular XLink.)
*
* These ought to be handled in the attribute methods.
*/
$this->state->current_token->namespace = 'math';
$this->insert_html_element( $this->state->current_token );
if ( $this->state->current_token->has_self_closing_flag ) {
$this->state->stack_of_open_elements->pop();
}
return true;
/*
* > A start tag whose tag name is "svg"
*/
case '+SVG':
$this->reconstruct_active_formatting_elements();
/*
* @todo Adjust SVG attributes for the token. (This fixes the case of SVG attributes that are not all lowercase.)
* @todo Adjust foreign attributes for the token. (This fixes the use of namespaced attributes, in particular XLink in SVG.)
*
* These ought to be handled in the attribute methods.
*/
$this->state->current_token->namespace = 'svg';
$this->insert_html_element( $this->state->current_token );
if ( $this->state->current_token->has_self_closing_flag ) {
$this->state->stack_of_open_elements->pop();
}
return true;
/*
* > A start tag whose tag name is one of: "caption", "col", "colgroup",
* > "frame", "head", "tbody", "td", "tfoot", "th", "thead", "tr"
*/
case '+CAPTION':
case '+COL':
case '+COLGROUP':
case '+FRAME':
case '+HEAD':
case '+TBODY':
case '+TD':
case '+TFOOT':
case '+TH':
case '+THEAD':
case '+TR':
// Parse error. Ignore the token.
return $this->step();
}
if ( ! parent::is_tag_closer() ) {
/*
* > Any other start tag
*/
$this->reconstruct_active_formatting_elements();
$this->insert_html_element( $this->state->current_token );
return true;
} else {
/*
* > Any other end tag
*/
return $this->in_body_any_other_end_tag();
}
$this->bail( 'Should not have been able to reach end of IN BODY processing. Check HTML API code.' );
// This unnecessary return prevents tools from inaccurately reporting type errors.
return false;
}
/**
* Applies the "any other end tag" parsing instructions for the IN BODY insertion mode.
*
* @since 7.1.0
* @ignore
*
* @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
*
* @see https://html.spec.whatwg.org/#parsing-main-inbody
* @see WP_HTML_Processor::step_in_body
*
* @return bool Whether an element was found.
*/
private function in_body_any_other_end_tag(): bool {
$token_name = $this->get_token_name();
/*
* Find the corresponding tag opener in the stack of open elements, if
* it exists before reaching a special element, which provides a kind
* of boundary in the stack. For example, a `</custom-tag>` should not
* close anything beyond its containing `P` or `DIV` element.
*/
foreach ( $this->state->stack_of_open_elements->walk_up() as $node ) {
if ( 'html' === $node->namespace && $token_name === $node->node_name ) {
break;
}
if ( self::is_special( $node ) ) {
// This is a parse error, ignore the token.
return $this->step();
}
}
$this->generate_implied_end_tags( $token_name );
if ( $node !== $this->state->stack_of_open_elements->current_node() ) {
// @todo Record parse error: this error doesn't impact parsing.
}
foreach ( $this->state->stack_of_open_elements->walk_up() as $item ) {
$this->state->stack_of_open_elements->pop();
if ( $node === $item ) {
return true;
}
}
$this->bail( 'Should not have been able to reach end of "any other end tag" IN BODY processing. Check HTML API code.' );
// This unnecessary return prevents tools from inaccurately reporting type errors.
return false;
}
/**
* Parses next element in the 'in table' insertion mode.
*
* This internal function performs the 'in table' insertion mode
* logic for the generalized WP_HTML_Processor::step() function.
*
* @since 6.7.0
* @ignore
*
* @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
*
* @see https://html.spec.whatwg.org/#parsing-main-intable
* @see WP_HTML_Processor::step
*
* @return bool Whether an element was found.
*/
private function step_in_table(): bool {
$token_name = $this->get_token_name();
$token_type = $this->get_token_type();
$op_sigil = '#tag' === $token_type ? ( parent::is_tag_closer() ? '-' : '+' ) : '';
$op = "{$op_sigil}{$token_name}";
switch ( $op ) {
/*
* > A character token, if the current node is table,
* > tbody, template, tfoot, thead, or tr element
*/
case '#text':
$current_node = $this->state->stack_of_open_elements->current_node();
Changelog
| Version | Description |
|---|---|
| 6.7.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.