private function step_after_head(): bool {
$token_name = $this->get_token_name();
$token_type = $this->get_token_type();
$is_closer = parent::is_tag_closer();
$op_sigil = '#tag' === $token_type ? ( $is_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
*/
case '#text':
if ( parent::TEXT_IS_WHITESPACE === $this->text_node_classification ) {
// Insert the character.
$this->insert_html_element( $this->state->current_token );
return true;
}
goto after_head_anything_else;
break;
/*
* > A comment token
*/
case '#comment':
case '#funky-comment':
case '#presumptuous-tag':
$this->insert_html_element( $this->state->current_token );
return true;
/*
* > A DOCTYPE token
*/
case 'html':
// Parse error: ignore the token.
return $this->step();
/*
* > A start tag whose tag name is "html"
*/
case '+HTML':
return $this->step_in_body();
/*
* > A start tag whose tag name is "body"
*/
case '+BODY':
$this->insert_html_element( $this->state->current_token );
$this->state->frameset_ok = false;
$this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_IN_BODY;
return true;
/*
* > A start tag whose tag name is "frameset"
*/
case '+FRAMESET':
$this->insert_html_element( $this->state->current_token );
$this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_IN_FRAMESET;
return true;
/*
* > A start tag whose tag name is one of: "base", "basefont", "bgsound",
* > "link", "meta", "noframes", "script", "style", "template", "title"
*
* Anything here is a parse error.
*/
case '+BASE':
case '+BASEFONT':
case '+BGSOUND':
case '+LINK':
case '+META':
case '+NOFRAMES':
case '+SCRIPT':
case '+STYLE':
case '+TEMPLATE':
case '+TITLE':
/*
* > Push the node pointed to by the head element pointer onto the stack of open elements.
* > Process the token using the rules for the "in head" insertion mode.
* > Remove the node pointed to by the head element pointer from the stack of open elements. (It might not be the current node at this point.)
*/
$this->bail( 'Cannot process elements after HEAD which reopen the HEAD element.' );
/*
* Do not leave this break in when adding support; it's here to prevent
* WPCS from getting confused at the switch structure without a return,
* because it doesn't know that `bail()` always throws.
*/
break;
/*
* > An end tag whose tag name is "template"
*/
case '-TEMPLATE':
return $this->step_in_head();
/*
* > An end tag whose tag name is one of: "body", "html", "br"
*
* Closing BR tags are always reported by the Tag Processor as opening tags.
*/
case '-BODY':
case '-HTML':
/*
* > Act as described in the "anything else" entry below.
*/
goto after_head_anything_else;
break;
}
/*
* > A start tag whose tag name is "head"
* > Any other end tag
*/
if ( '+HEAD' === $op || $is_closer ) {
// Parse error: ignore the token.
return $this->step();
}
/*
* > 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 );
}