WP_HTML_Processor::step_in_template()privateWP 6.7.0

Parses next element in the 'in template' insertion mode.

This internal function performs the 'in template' insertion mode logic for the generalized WP_HTML_Processor::step() function.

Method of the class: WP_HTML_Processor{}

No Hooks.

Return

true|false. Whether an element was found.

Usage

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

Notes

Changelog

Since 6.7.0 Introduced.
Since 6.7.0 Stub implementation.

WP_HTML_Processor::step_in_template() code WP 6.7.1

private function step_in_template(): bool {
	$token_name = $this->get_token_name();
	$token_type = $this->get_token_type();
	$is_closer  = $this->is_tag_closer();
	$op_sigil   = '#tag' === $token_type ? ( $is_closer ? '-' : '+' ) : '';
	$op         = "{$op_sigil}{$token_name}";

	switch ( $op ) {
		/*
		 * > A character token
		 * > A comment token
		 * > A DOCTYPE token
		 */
		case '#text':
		case '#comment':
		case '#funky-comment':
		case '#presumptuous-tag':
		case 'html':
			return $this->step_in_body();

		/*
		 * > 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"
		 */
		case '+BASE':
		case '+BASEFONT':
		case '+BGSOUND':
		case '+LINK':
		case '+META':
		case '+NOFRAMES':
		case '+SCRIPT':
		case '+STYLE':
		case '+TEMPLATE':
		case '+TITLE':
		case '-TEMPLATE':
			return $this->step_in_head();

		/*
		 * > A start tag whose tag name is one of: "caption", "colgroup", "tbody", "tfoot", "thead"
		 */
		case '+CAPTION':
		case '+COLGROUP':
		case '+TBODY':
		case '+TFOOT':
		case '+THEAD':
			array_pop( $this->state->stack_of_template_insertion_modes );
			$this->state->stack_of_template_insertion_modes[] = WP_HTML_Processor_State::INSERTION_MODE_IN_TABLE;
			$this->state->insertion_mode                      = WP_HTML_Processor_State::INSERTION_MODE_IN_TABLE;
			return $this->step( self::REPROCESS_CURRENT_NODE );

		/*
		 * > A start tag whose tag name is "col"
		 */
		case '+COL':
			array_pop( $this->state->stack_of_template_insertion_modes );
			$this->state->stack_of_template_insertion_modes[] = WP_HTML_Processor_State::INSERTION_MODE_IN_COLUMN_GROUP;
			$this->state->insertion_mode                      = WP_HTML_Processor_State::INSERTION_MODE_IN_COLUMN_GROUP;
			return $this->step( self::REPROCESS_CURRENT_NODE );

		/*
		 * > A start tag whose tag name is "tr"
		 */
		case '+TR':
			array_pop( $this->state->stack_of_template_insertion_modes );
			$this->state->stack_of_template_insertion_modes[] = WP_HTML_Processor_State::INSERTION_MODE_IN_TABLE_BODY;
			$this->state->insertion_mode                      = WP_HTML_Processor_State::INSERTION_MODE_IN_TABLE_BODY;
			return $this->step( self::REPROCESS_CURRENT_NODE );

		/*
		 * > A start tag whose tag name is one of: "td", "th"
		 */
		case '+TD':
		case '+TH':
			array_pop( $this->state->stack_of_template_insertion_modes );
			$this->state->stack_of_template_insertion_modes[] = WP_HTML_Processor_State::INSERTION_MODE_IN_ROW;
			$this->state->insertion_mode                      = WP_HTML_Processor_State::INSERTION_MODE_IN_ROW;
			return $this->step( self::REPROCESS_CURRENT_NODE );
	}

	/*
	 * > Any other start tag
	 */
	if ( ! $is_closer ) {
		array_pop( $this->state->stack_of_template_insertion_modes );
		$this->state->stack_of_template_insertion_modes[] = WP_HTML_Processor_State::INSERTION_MODE_IN_BODY;
		$this->state->insertion_mode                      = WP_HTML_Processor_State::INSERTION_MODE_IN_BODY;
		return $this->step( self::REPROCESS_CURRENT_NODE );
	}

	/*
	 * > Any other end tag
	 */
	if ( $is_closer ) {
		// Parse error: ignore the token.
		return $this->step();
	}

	/*
	 * > An end-of-file token
	 */
	if ( ! $this->state->stack_of_open_elements->contains( 'TEMPLATE' ) ) {
		// Stop parsing.
		return false;
	}

	// @todo Indicate a parse error once it's possible.
	$this->state->stack_of_open_elements->pop_until( 'TEMPLATE' );
	$this->state->active_formatting_elements->clear_up_to_last_marker();
	array_pop( $this->state->stack_of_template_insertion_modes );
	$this->reset_insertion_mode_appropriately();
	return $this->step( self::REPROCESS_CURRENT_NODE );
}