WP_HTML_Processor::run_adoption_agency_algorithm()

In this article

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/#adoption-agency-algorithm instead.

Runs the adoption agency algorithm.

Description

See also

Source


	/*
	 * > Anything else
	 * > Insert an HTML element for a "body" start tag token with no attributes.
	 */
	after_head_anything_else:
	$this->insert_virtual_node( 'BODY' );
	$this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_IN_BODY;
	return $this->step( self::REPROCESS_CURRENT_NODE );
}

/**
 * Parses next element in the 'in body' insertion mode.
 *
 * This internal function performs the 'in body' insertion mode
 * logic for the generalized WP_HTML_Processor::step() function.
 *
 * @since 6.4.0
 *
 * @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
 *
 * @see https://html.spec.whatwg.org/#parsing-main-inbody
 * @see WP_HTML_Processor::step
 *
 * @return bool Whether an element was found.
 */
private function step_in_body(): 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 ) {
		case '#text':
			/*
			 * > A character token that is U+0000 NULL
			 *
			 * Any successive sequence of NULL bytes is ignored and won't
			 * trigger active format reconstruction. Therefore, if the text
			 * only comprises NULL bytes then the token should be ignored
			 * here, but if there are any other characters in the stream
			 * the active formats should be reconstructed.
			 */
			if ( parent::TEXT_IS_NULL_SEQUENCE === $this->text_node_classification ) {
				// Parse error: ignore the token.
				return $this->step();
			}

			$this->reconstruct_active_formatting_elements();

			/*
			 * Whitespace-only text does not affect the frameset-ok flag.
			 * It is probably inter-element whitespace, but it may also
			 * contain character references which decode only to whitespace.
			 */
			if ( parent::TEXT_IS_GENERIC === $this->text_node_classification ) {
				$this->state->frameset_ok = false;
			}

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

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

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

		/*
		 * > A start tag whose tag name is "html"
		 */
		case '+HTML':
			if ( ! $this->state->stack_of_open_elements->contains( 'TEMPLATE' ) ) {
				/*
				 * > Otherwise, for each attribute on the token, check to see if the attribute
				 * > is already present on the top element of the stack of open elements. If
				 * > it is not, add the attribute and its corresponding value to that element.
				 *
				 * This parser does not currently support this behavior: ignore the token.
				 */
			}

			// Ignore the token.
			return $this->step();

		/*
		 * > 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':

Changelog

VersionDescription
6.4.0Introduced.

User Contributed Notes

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