Skip to content

Commit 724dde1

Browse files
committed
Add some tag handling from WordPress#6972
This includes template support in body
1 parent 2eb1e01 commit 724dde1

1 file changed

Lines changed: 69 additions & 8 deletions

File tree

src/wp-includes/html-api/class-wp-html-processor.php

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,12 +1107,6 @@ private function step_in_body() {
11071107
$op = "{$op_sigil}{$token_name}";
11081108

11091109
switch ( $op ) {
1110-
case '#comment':
1111-
case '#funky-comment':
1112-
case '#presumptuous-tag':
1113-
$this->insert_html_element( $this->state->current_token );
1114-
return true;
1115-
11161110
case '#text':
11171111
$this->reconstruct_active_formatting_elements();
11181112

@@ -1149,10 +1143,77 @@ private function step_in_body() {
11491143
$this->insert_html_element( $this->state->current_token );
11501144
return true;
11511145

1146+
case '#comment':
1147+
case '#funky-comment':
1148+
case '#presumptuous-tag':
1149+
$this->insert_html_element( $this->state->current_token );
1150+
return true;
1151+
1152+
/*
1153+
* > A DOCTYPE token
1154+
* > Parse error. Ignore the token.
1155+
*/
11521156
case 'html':
1157+
return $this->step();
1158+
1159+
/*
1160+
* > A start tag whose tag name is "html"
1161+
*/
1162+
case '+HTML':
1163+
if ( ! $this->state->stack_of_open_elements->contains( 'TEMPLATE' ) ) {
1164+
/*
1165+
* > Otherwise, for each attribute on the token, check to see if the attribute
1166+
* > is already present on the top element of the stack of open elements. If
1167+
* > it is not, add the attribute and its corresponding value to that element.
1168+
*
1169+
* This parser does not currently support this behavior: ignore the token.
1170+
*/
1171+
}
1172+
1173+
// Ignore the token.
1174+
return $this->step();
1175+
1176+
/*
1177+
* > A start tag whose tag name is one of: "base", "basefont", "bgsound", "link",
1178+
* > "meta", "noframes", "script", "style", "template", "title"
1179+
* >
1180+
* > An end tag whose tag name is "template"
1181+
*/
1182+
case '+BASE':
1183+
case '+BASEFONT':
1184+
case '+BGSOUND':
1185+
case '+LINK':
1186+
case '+META':
1187+
case '+NOFRAMES':
1188+
case '+SCRIPT':
1189+
case '+STYLE':
1190+
case '+TEMPLATE':
1191+
case '+TITLE':
1192+
case '-TEMPLATE':
1193+
return $this->step_in_head();
1194+
1195+
/*
1196+
* > A start tag whose tag name is "body"
1197+
*
1198+
* This tag in the IN BODY insertion mode is a parse error.
1199+
*/
1200+
case '+BODY':
1201+
if (
1202+
1 === $this->state->stack_of_open_elements->count() ||
1203+
'BODY' !== $this->state->stack_of_open_elements->at( 2 ) ||
1204+
$this->state->stack_of_open_elements->contains( 'TEMPLATE' )
1205+
) {
1206+
// Ignore the token.
1207+
return $this->step();
1208+
}
1209+
11531210
/*
1154-
* > A DOCTYPE token
1155-
* > Parse error. Ignore the token.
1211+
* > Otherwise, set the frameset-ok flag to "not ok"; then, for each attribute
1212+
* > on the token, check to see if the attribute is already present on the body
1213+
* > element (the second element) on the stack of open elements, and if it is
1214+
* > not, add the attribute and its corresponding value to that element.
1215+
*
1216+
* This parser does not currently support this behavior: ignore the token.
11561217
*/
11571218
return $this->step();
11581219

0 commit comments

Comments
 (0)