From 85de4aa70dd4f02d1aeb87277b65535438530bcd Mon Sep 17 00:00:00 2001 From: Dennis Snell Date: Fri, 19 Jan 2024 22:05:37 +0000 Subject: [PATCH] HTML API: Add support for PRE and LISTING elements. Adds support for the following HTML elements to the HTML Processor: - PRE, LISTING Previously, these elements were not supported and the HTML Processor would bail when encountering them. Now, with this patch applied, it will proceed to parse an HTML document when encountering those tags. Developed in WordPress/wordpress-develop#5903 Props jonsurrell, dmsnell Fixes #60283 git-svn-id: https://develop.svn.wordpress.org/trunk@57317 602fd350-edb4-49c9-b593-d223f7449a82 --- .../html-api/class-wp-html-processor.php | 20 +++++++++++++++---- .../tests/html-api/wpHtmlProcessor.php | 2 -- .../html-api/wpHtmlProcessorBreadcrumbs.php | 2 -- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/wp-includes/html-api/class-wp-html-processor.php b/src/wp-includes/html-api/class-wp-html-processor.php index 34443a50bb5dd..65fcfbe236ee5 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -102,7 +102,7 @@ * - Containers: ADDRESS, BLOCKQUOTE, DETAILS, DIALOG, DIV, FOOTER, HEADER, MAIN, MENU, SPAN, SUMMARY. * - Custom elements: All custom elements are supported. :) * - Form elements: BUTTON, DATALIST, FIELDSET, LABEL, LEGEND, METER, PROGRESS, SEARCH. - * - Formatting elements: B, BIG, CODE, EM, FONT, I, SMALL, STRIKE, STRONG, TT, U, WBR. + * - Formatting elements: B, BIG, CODE, EM, FONT, I, PRE, SMALL, STRIKE, STRONG, TT, U, WBR. * - Heading elements: H1, H2, H3, H4, H5, H6, HGROUP. * - Links: A. * - Lists: DD, DL, DT, LI, OL, LI. @@ -112,7 +112,7 @@ * - Sectioning elements: ARTICLE, ASIDE, HR, NAV, SECTION. * - Templating elements: SLOT. * - Text decoration: RUBY. - * - Deprecated elements: ACRONYM, BLINK, CENTER, DIR, ISINDEX, KEYGEN, MULTICOL, NEXTID, SPACER. + * - Deprecated elements: ACRONYM, BLINK, CENTER, DIR, ISINDEX, KEYGEN, LISTING, MULTICOL, NEXTID, SPACER. * * ### Supported markup * @@ -684,10 +684,12 @@ private function step_in_body() { case '-FOOTER': case '-HEADER': case '-HGROUP': + case '-LISTING': case '-MAIN': case '-MENU': case '-NAV': case '-OL': + case '-PRE': case '-SEARCH': case '-SECTION': case '-SUMMARY': @@ -732,6 +734,18 @@ private function step_in_body() { $this->insert_html_element( $this->state->current_token ); return true; + /* + * > A start tag whose tag name is one of: "pre", "listing" + */ + case '+PRE': + case '+LISTING': + if ( $this->state->stack_of_open_elements->has_p_in_button_scope() ) { + $this->close_a_p_element(); + } + $this->insert_html_element( $this->state->current_token ); + $this->state->frameset_ok = false; + return true; + /* * > An end tag whose tag name is one of: "h1", "h2", "h3", "h4", "h5", "h6" */ @@ -1007,7 +1021,6 @@ private function step_in_body() { case 'INPUT': case 'LI': case 'LINK': - case 'LISTING': case 'MARQUEE': case 'MATH': case 'META': @@ -1021,7 +1034,6 @@ private function step_in_body() { case 'OPTION': case 'PARAM': case 'PLAINTEXT': - case 'PRE': case 'RB': case 'RP': case 'RT': diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessor.php b/tests/phpunit/tests/html-api/wpHtmlProcessor.php index c556d7e36a76f..2e17b1a9a0df2 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessor.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessor.php @@ -254,7 +254,6 @@ public function data_unsupported_special_in_body_tags() { 'IFRAME' => array( 'IFRAME' ), 'INPUT' => array( 'INPUT' ), 'LINK' => array( 'LINK' ), - 'LISTING' => array( 'LISTING' ), 'MARQUEE' => array( 'MARQUEE' ), 'MATH' => array( 'MATH' ), 'META' => array( 'META' ), @@ -267,7 +266,6 @@ public function data_unsupported_special_in_body_tags() { 'OPTION' => array( 'OPTION' ), 'PARAM' => array( 'PARAM' ), 'PLAINTEXT' => array( 'PLAINTEXT' ), - 'PRE' => array( 'PRE' ), 'RB' => array( 'RB' ), 'RP' => array( 'RP' ), 'RT' => array( 'RT' ), diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php b/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php index 7da3730910cf5..4e769ab2ca293 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php @@ -176,7 +176,6 @@ public function data_unsupported_elements() { 'IFRAME', 'INPUT', 'LINK', - 'LISTING', // Deprecated, use PRE instead. 'MARQUEE', // Deprecated. 'MATH', 'META', @@ -188,7 +187,6 @@ public function data_unsupported_elements() { 'OPTGROUP', 'OPTION', 'PLAINTEXT', // Neutralized. - 'PRE', 'RB', // Neutralized. 'RP', 'RT',