Parses next element in the ‘before html’ insertion mode.
Description
This internal function performs the ‘before html’ insertion mode logic for the generalized WP_HTML_Processor::step() function.
See also
Source
/**
* Escapes decoded text for HTML serialization.
*
* Use for:
* - Attribute values.
* - Text in ordinary (data-state) elements and in the RCDATA elements
* (TITLE and TEXTAREA).
* - Text in foreign content (elements not in the HTML namespace).
*
* Do not use for text in the RAWTEXT elements (STYLE, XMP, IFRAME,
* NOEMBED, NOFRAMES), HTML SCRIPT elements, or PLAINTEXT elements,
* whose contents serialize without escaping.
*
* @since 7.1.0
* @ignore
*
* @param string $text Decoded text to escape.
* @return string Escaped text.
*/
private static function escape_text_for_serialization( string $text ): string {
$text = htmlspecialchars( $text, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML5, 'UTF-8' );
$text = str_replace( "\r", '
', $text );
return str_replace( "\x00", "\u{FFFD}", $text );
}
/**
* Parses next element in the 'initial' insertion mode.
*
* This internal function performs the 'initial' insertion mode
* logic for the generalized WP_HTML_Processor::step() function.
*
* @since 6.7.0
* @ignore
*
* @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
*
* @see https://html.spec.whatwg.org/#the-initial-insertion-mode
* @see WP_HTML_Processor::step
*
* @return bool Whether an element was found.
*/
private function step_initial(): 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 ) {
/*
* > A character token that is one of U+0009 CHARACTER TABULATION,
* > U+000A LINE FEED (LF), U+000C FORM FEED (FF),
* > U+000D CARRIAGE RETURN (CR), or U+0020 SPACE
*
* Parse error: ignore the token.
*/
case '#text':
if ( parent::TEXT_IS_WHITESPACE === $this->text_node_classification ) {
return $this->step();
}
goto initial_anything_else;
break;
/*
* > A comment token
* > A processing instruction token
*/
case '#comment':
case '#funky-comment':
case '#presumptuous-tag':
case '#processing-instruction':
$this->insert_html_element( $this->state->current_token );
return true;
/*
* > A DOCTYPE token
*/
case 'html':
$doctype = $this->get_doctype_info();
if ( null !== $doctype && 'quirks' === $doctype->indicated_compatibility_mode ) {
Changelog
| Version | Description |
|---|---|
| 6.7.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.