WP_HTML_Processor::step_in_select()privateWP 6.7.0

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

This internal function performs the 'in select' 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_select(): bool;

Notes

Changelog

Since 6.7.0 Introduced.

WP_HTML_Processor::step_in_select() code WP 6.7.1

private function step_in_select(): 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 ) {
		/*
		 * > Any other character token
		 */
		case '#text':
			/*
			 * > A character token that is U+0000 NULL
			 *
			 * If a text node only comprises null bytes then it should be
			 * entirely ignored and should not return to calling code.
			 */
			if ( parent::TEXT_IS_NULL_SEQUENCE === $this->text_node_classification ) {
				// Parse error: ignore the token.
				return $this->step();
			}

			$this->insert_html_element( $this->state->current_token );
			return true;

		/*
		 * > A comment token
		 */
		case '#comment':
		case '#funky-comment':
		case '#presumptuous-tag':
			$this->insert_html_element( $this->state->current_token );
			return true;

		/*
		 * > A DOCTYPE token
		 */
		case 'html':
			// Parse error: ignore the token.
			return $this->step();

		/*
		 * > A start tag whose tag name is "html"
		 */
		case '+HTML':
			return $this->step_in_body();

		/*
		 * > A start tag whose tag name is "option"
		 */
		case '+OPTION':
			if ( $this->state->stack_of_open_elements->current_node_is( 'OPTION' ) ) {
				$this->state->stack_of_open_elements->pop();
			}
			$this->insert_html_element( $this->state->current_token );
			return true;

		/*
		 * > A start tag whose tag name is "optgroup"
		 * > A start tag whose tag name is "hr"
		 *
		 * These rules are identical except for the treatment of the self-closing flag and
		 * the subsequent pop of the HR void element, all of which is handled elsewhere in the processor.
		 */
		case '+OPTGROUP':
		case '+HR':
			if ( $this->state->stack_of_open_elements->current_node_is( 'OPTION' ) ) {
				$this->state->stack_of_open_elements->pop();
			}

			if ( $this->state->stack_of_open_elements->current_node_is( 'OPTGROUP' ) ) {
				$this->state->stack_of_open_elements->pop();
			}

			$this->insert_html_element( $this->state->current_token );
			return true;

		/*
		 * > An end tag whose tag name is "optgroup"
		 */
		case '-OPTGROUP':
			$current_node = $this->state->stack_of_open_elements->current_node();
			if ( $current_node && 'OPTION' === $current_node->node_name ) {
				foreach ( $this->state->stack_of_open_elements->walk_up( $current_node ) as $parent ) {
					break;
				}
				if ( $parent && 'OPTGROUP' === $parent->node_name ) {
					$this->state->stack_of_open_elements->pop();
				}
			}

			if ( $this->state->stack_of_open_elements->current_node_is( 'OPTGROUP' ) ) {
				$this->state->stack_of_open_elements->pop();
				return true;
			}

			// Parse error: ignore the token.
			return $this->step();

		/*
		 * > An end tag whose tag name is "option"
		 */
		case '-OPTION':
			if ( $this->state->stack_of_open_elements->current_node_is( 'OPTION' ) ) {
				$this->state->stack_of_open_elements->pop();
				return true;
			}

			// Parse error: ignore the token.
			return $this->step();

		/*
		 * > An end tag whose tag name is "select"
		 * > A start tag whose tag name is "select"
		 *
		 * > It just gets treated like an end tag.
		 */
		case '-SELECT':
		case '+SELECT':
			if ( ! $this->state->stack_of_open_elements->has_element_in_select_scope( 'SELECT' ) ) {
				// Parse error: ignore the token.
				return $this->step();
			}
			$this->state->stack_of_open_elements->pop_until( 'SELECT' );
			$this->reset_insertion_mode_appropriately();
			return true;

		/*
		 * > A start tag whose tag name is one of: "input", "keygen", "textarea"
		 *
		 * All three of these tags are considered a parse error when found in this insertion mode.
		 */
		case '+INPUT':
		case '+KEYGEN':
		case '+TEXTAREA':
			if ( ! $this->state->stack_of_open_elements->has_element_in_select_scope( 'SELECT' ) ) {
				// Ignore the token.
				return $this->step();
			}
			$this->state->stack_of_open_elements->pop_until( 'SELECT' );
			$this->reset_insertion_mode_appropriately();
			return $this->step( self::REPROCESS_CURRENT_NODE );

		/*
		 * > A start tag whose tag name is one of: "script", "template"
		 * > An end tag whose tag name is "template"
		 */
		case '+SCRIPT':
		case '+TEMPLATE':
		case '-TEMPLATE':
			return $this->step_in_head();
	}

	/*
	 * > Anything else
	 * >   Parse error: ignore the token.
	 */
	return $this->step();
}