WP_Block_Processor::is_non_whitespace_html(): bool

Indicates if the matched delimiter is an HTML span and comprises more than whitespace characters, i.e. contains real content.

Description

Many block serializers introduce newlines between block delimiters, so the presence of top-level non-block content does not imply that there are “real” freeform HTML blocks. Checking if there is content beyond whitespace is a more certain check, such as for determining whether to load CSS for the freeform or fallback block type.

See also

Return

bool Whether the currently-matched delimiter is an HTML span containing non-whitespace text.

Source

public function is_non_whitespace_html(): bool {
	if ( ! $this->is_html() ) {
		return false;
	}

	$length = $this->matched_delimiter_at - $this->after_previous_delimiter;

	$whitespace_length = strspn(
		$this->source_text,
		" \t\f\r\n",
		$this->after_previous_delimiter,
		$length
	);

	return $whitespace_length !== $length;
}

Changelog

VersionDescription
6.9.0Introduced.

User Contributed Notes

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