WP_HTML_Processor::step_initial(): bool

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only by core. It is listed here for completeness.

Parses next element in the ‘initial’ insertion mode.

Description

This internal function performs the ‘initial’ insertion mode logic for the generalized WP_HTML_Processor::step() function.

See also

Return

bool Whether an element was found.

Source

		isset( $serialized_attribute_name[0] ) &&
		'=' === $serialized_attribute_name[0]
	) {
		$html .= '=""';
	}

	$html .= " {$serialized_attribute_name}";
	$value = $this->get_attribute( $attribute_name );

	if ( is_string( $value ) ) {
		$html .= '="' . self::escape_text_for_serialization( $value ) . '"';
	}

	$previous_attribute_was_true = true === $value;
}

if ( ! $in_html && $this->has_self_closing_flag() ) {
	$html .= ' /';
}

$html .= '>';

/*
 * The HTML parser strips a leading newline immediately after the start
 * tag of TEXTAREA, PRE, and LISTING elements in HTML content. When serializing,
 * prepend a leading newline to ensure the semantic HTML content is preserved.
 *
 * For example, `<pre>\n\nX</pre>` must not become `<pre>\nX</pre>` because its content
 * has changed. However, `<pre>X</pre>` and `<pre>\nX</pre>` are _equivalent_.
 *
 * > A start tag whose tag name is "textarea"
 * >   …
 * >   If the next token is a U+000A LINE FEED (LF) character token, then ignore
 * >   that token and move on to the next one. (Newlines at the start of textarea
 * >   elements are ignored as an authoring convenience.)
 *
 * > A start tag whose tag name is one of: "pre", "listing"
 * >   …
 * >   If the next token is a U+000A LINE FEED (LF) character token, then ignore
 * >   that token and move on to the next one. (Newlines at the start of pre blocks
 * >   are ignored as an authoring convenience.)
 *
 * @see https://html.spec.whatwg.org/multipage/parsing.html
 */
if ( $in_html && ( 'TEXTAREA' === $tag_name || 'PRE' === $tag_name || 'LISTING' === $tag_name ) ) {
	$html .= "\n";
}

// Flush out self-contained elements.
if ( $in_html && in_array( $tag_name, array( 'IFRAME', 'NOEMBED', 'NOFRAMES', 'SCRIPT', 'STYLE', 'TEXTAREA', 'TITLE', 'XMP' ), true ) ) {
	$text = $this->get_modifiable_text();

	switch ( $tag_name ) {
		case 'IFRAME':
		case 'NOEMBED':

Changelog

VersionDescription
6.7.0Introduced.

User Contributed Notes

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