WP_HTML_Processor::step_in_cell(): bool

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Use https://html.spec.whatwg.org/#parsing-main-intd instead.

Parses next element in the ‘in cell’ insertion mode.

Description

This internal function performs the ‘in cell’ insertion mode logic for the generalized WP_HTML_Processor::step() function.

See also

Return

bool Whether an element was found.

Source

private function step_in_cell(): bool {
	$tag_name = $this->get_tag();
	$op_sigil = $this->is_tag_closer() ? '-' : '+';
	$op       = "{$op_sigil}{$tag_name}";

	switch ( $op ) {
		/*
		 * > An end tag whose tag name is one of: "td", "th"
		 */
		case '-TD':
		case '-TH':
			if ( ! $this->state->stack_of_open_elements->has_element_in_table_scope( $tag_name ) ) {
				// Parse error: ignore the token.
				return $this->step();
			}

			$this->generate_implied_end_tags();

			/*
			 * @todo This needs to check if the current node is an HTML element, meaning that
			 *       when SVG and MathML support is added, this needs to differentiate between an
			 *       HTML element of the given name, such as `<center>`, and a foreign element of
			 *       the same given name.
			 */
			if ( ! $this->state->stack_of_open_elements->current_node_is( $tag_name ) ) {
				// @todo Indicate a parse error once it's possible.
			}

			$this->state->stack_of_open_elements->pop_until( $tag_name );
			$this->state->active_formatting_elements->clear_up_to_last_marker();
			$this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_IN_ROW;
			return true;

		/*
		 * > A start tag whose tag name is one of: "caption", "col", "colgroup", "tbody", "td",
		 * > "tfoot", "th", "thead", "tr"
		 */
		case '+CAPTION':
		case '+COL':
		case '+COLGROUP':
		case '+TBODY':
		case '+TD':
		case '+TFOOT':
		case '+TH':
		case '+THEAD':
		case '+TR':
			/*
			 * > Assert: The stack of open elements has a td or th element in table scope.
			 *
			 * Nothing to do here, except to verify in tests that this never appears.
			 */

			$this->close_cell();
			return $this->step( self::REPROCESS_CURRENT_NODE );

		/*
		 * > An end tag whose tag name is one of: "body", "caption", "col", "colgroup", "html"
		 */
		case '-BODY':
		case '-CAPTION':
		case '-COL':
		case '-COLGROUP':
		case '-HTML':
			// Parse error: ignore the token.
			return $this->step();

		/*
		 * > An end tag whose tag name is one of: "table", "tbody", "tfoot", "thead", "tr"
		 */
		case '-TABLE':
		case '-TBODY':
		case '-TFOOT':
		case '-THEAD':
		case '-TR':
			if ( ! $this->state->stack_of_open_elements->has_element_in_table_scope( $tag_name ) ) {
				// Parse error: ignore the token.
				return $this->step();
			}
			$this->close_cell();
			return $this->step( self::REPROCESS_CURRENT_NODE );
	}

	/*
	 * > Anything else
	 * >   Process the token using the rules for the "in body" insertion mode.
	 */
	return $this->step_in_body();
}

Changelog

VersionDescription
6.7.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.