WP_HTML_Processor::step_in_caption(): 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-incaption instead.

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

Description

This internal function performs the ‘in caption’ 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_caption(): 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 "caption"
		 * > A start tag whose tag name is one of: "caption", "col", "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"
		 * > An end tag whose tag name is "table"
		 *
		 * These tag handling rules are identical except for the final instruction.
		 * Handle them in a single block.
		 */
		case '-CAPTION':
		case '+CAPTION':
		case '+COL':
		case '+COLGROUP':
		case '+TBODY':
		case '+TD':
		case '+TFOOT':
		case '+TH':
		case '+THEAD':
		case '+TR':
		case '-TABLE':
			if ( ! $this->state->stack_of_open_elements->has_element_in_table_scope( 'CAPTION' ) ) {
				// Parse error: ignore the token.
				return $this->step();
			}

			$this->generate_implied_end_tags();
			if ( ! $this->state->stack_of_open_elements->current_node_is( 'CAPTION' ) ) {
				// @todo Indicate a parse error once it's possible.
			}

			$this->state->stack_of_open_elements->pop_until( 'CAPTION' );
			$this->state->active_formatting_elements->clear_up_to_last_marker();
			$this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_IN_TABLE;

			// If this is not a CAPTION end tag, the token should be reprocessed.
			if ( '-CAPTION' === $op ) {
				return true;
			}
			return $this->step( self::REPROCESS_CURRENT_NODE );

		/**
		 * > An end tag whose tag name is one of: "body", "col", "colgroup", "html", "tbody", "td", "tfoot", "th", "thead", "tr"
		 */
		case '-BODY':
		case '-COL':
		case '-COLGROUP':
		case '-HTML':
		case '-TBODY':
		case '-TD':
		case '-TFOOT':
		case '-TH':
		case '-THEAD':
		case '-TR':
			// Parse error: ignore the token.
			return $this->step();
	}

	/**
	 * > 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.