WP_HTML_Processor::get_breadcrumbs(): string[]|null

In this article

Computes the HTML breadcrumbs for the currently-matched node, if matched.

Description

Breadcrumbs start at the outermost parent and descend toward the matched element.
They always include the entire path from the root HTML node to the matched element.

Return

string[]|null Array of tag names representing path to matched node, if matched, otherwise NULL.

Source


	$token_namespace        = $node->namespace ?? $this->get_namespace();
	$token_has_self_closing = $node->has_self_closing_flag ?? $this->has_self_closing_flag();

	return ! (
		// Comments, text nodes, and other atomic tokens.
		'#' === $token_name[0] ||
		// Doctype declarations.
		'html' === $token_name ||
		// Void elements.
		self::is_void( $token_name ) ||
		// Special atomic elements.
		( 'html' === $token_namespace && in_array( $token_name, array( 'IFRAME', 'NOEMBED', 'NOFRAMES', 'SCRIPT', 'STYLE', 'TEXTAREA', 'TITLE', 'XMP' ), true ) ) ||
		// Self-closing elements in foreign content.
		( 'html' !== $token_namespace && $token_has_self_closing )
	);
}

/**
 * Steps through the HTML document and stop at the next tag, if any.
 *
 * @since 6.4.0
 *
 * @throws Exception When unable to allocate a bookmark for the next token in the input HTML document.
 *
 * @see self::PROCESS_NEXT_NODE
 * @see self::REPROCESS_CURRENT_NODE
 *
 * @param string $node_to_process Whether to parse the next node or reprocess the current node.
 * @return bool Whether a tag was matched.
 */
public function step( $node_to_process = self::PROCESS_NEXT_NODE ): bool {
	// Refuse to proceed if there was a previous error.
	if ( null !== $this->last_error ) {
		return false;
	}

	if ( self::REPROCESS_CURRENT_NODE !== $node_to_process ) {
		/*
		 * Void elements still hop onto the stack of open elements even though
		 * there's no corresponding closing tag. This is important for managing
		 * stack-based operations such as "navigate to parent node" or checking

Changelog

VersionDescription
6.4.0Introduced.

User Contributed Notes

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