WP_HTML_Processor::seek( string $bookmark_name ): bool

In this article

Moves the internal cursor in the HTML Processor to a given bookmark’s location.

Description

Be careful! Seeking backwards to a previous location resets the parser to the start of the document and reparses the entire contents up until it finds the sought-after bookmarked location.

In order to prevent accidental infinite loops, there’s a maximum limit on the number of times seek() can be called.

Parameters

$bookmark_namestringrequired
Jump to the place in the document identified by this bookmark name.

Return

bool Whether the internal cursor was successfully moved to the bookmark’s location.

Source

			$this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_AFTER_HEAD;
			return true;

		/*
		 * > An end tag whose tag name is one of: "body", "html", "br"
		 *
		 * BR tags are always reported by the Tag Processor as opening tags.
		 */
		case '-BODY':
		case '-HTML':
			/*
			 * > Act as described in the "anything else" entry below.
			 */
			goto in_head_anything_else;
			break;

		/*
		 * > A start tag whose tag name is "template"
		 *
		 * @todo Could the adjusted insertion location be anything other than the current location?
		 */
		case '+TEMPLATE':
			$this->state->active_formatting_elements->insert_marker();
			$this->state->frameset_ok = false;

			$this->state->insertion_mode                      = WP_HTML_Processor_State::INSERTION_MODE_IN_TEMPLATE;
			$this->state->stack_of_template_insertion_modes[] = WP_HTML_Processor_State::INSERTION_MODE_IN_TEMPLATE;

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

		/*
		 * > An end tag whose tag name is "template"
		 */
		case '-TEMPLATE':
			if ( ! $this->state->stack_of_open_elements->contains( 'TEMPLATE' ) ) {
				// @todo Indicate a parse error once it's possible.
				return $this->step();
			}

			$this->generate_implied_end_tags_thoroughly();
			if ( ! $this->state->stack_of_open_elements->current_node_is( 'TEMPLATE' ) ) {
				// @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 true;
	}

	/*
	 * > A start tag whose tag name is "head"
	 * > Any other end tag
	 */
	if ( '+HEAD' === $op || $is_closer ) {
		// Parse error: ignore the token.
		return $this->step();
	}

	/*
	 * > Anything else
	 */
	in_head_anything_else:
	$this->state->stack_of_open_elements->pop();
	$this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_AFTER_HEAD;
	return $this->step( self::REPROCESS_CURRENT_NODE );
}

/**
 * Parses next element in the 'in head noscript' insertion mode.
 *
 * This internal function performs the 'in head noscript' insertion mode
 * logic for the generalized WP_HTML_Processor::step() function.
 *
 * @since 6.7.0 Stub implementation.
 *
 * @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
 *
 * @see https://html.spec.whatwg.org/#parsing-main-inheadnoscript
 * @see WP_HTML_Processor::step
 *
 * @return bool Whether an element was found.
 */

Changelog

VersionDescription
6.4.0Introduced.

User Contributed Notes

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