WP_HTML_Processor::in_body_any_other_end_tag │ private │ WP 7.1.0

Applies the "any other end tag" parsing instructions for the IN BODY insertion mode.

Method of the class: WP_HTML_Processor{}

No Hooks.

Returns

bool. Whether an element was found.

Usage

// private - for code of main (parent) class only
$result = $this->in_body_any_other_end_tag(): bool;

Notes

See: https://html.spec.whatwg.org/#parsing-main-inbody
See: WP_HTML_Processor::step_in_body

Changelog

Since 7.1.0 Introduced.

WP_HTML_Processor::in_body_any_other_end_tag() code WP 7.1.4

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;
}