<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[57186] trunk: HTML API: Add support for H1-H6 elements in the HTML Processor.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/57186">57186</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/57186","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>Bernhard Reiter</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2023-12-13 17:51:42 +0000 (Wed, 13 Dec 2023)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>HTML API: Add support for H1-H6 elements in the HTML Processor.

Previously these have been unsupported, but in this patch, support is added for the tags so that the HTML Processor can process documents containing them.

There was a design discussion about introducing a constant to communicate "any of the H1 - H6 elements" but this posed a number of challenges that don't need to be answered in this patch. For the time being, because the HTML specification treats H1 - H6 specially as a single kind of element, the HTML Processor uses an internal hard-coded string to indicate this. By using a hard-coded string it's possible to avoid introducing a class constant which cannot be made private due to PHP's class design. In the future, this will probably appear as a special constant in a new constant-containing class.

Props dmsnell, jonsurrell.
Fixes <a href="https://core.trac.wordpress.org/ticket/60060">#60060</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludeshtmlapiclasswphtmlopenelementsphp">trunk/src/wp-includes/html-api/class-wp-html-open-elements.php</a></li>
<li><a href="#trunksrcwpincludeshtmlapiclasswphtmlprocessorphp">trunk/src/wp-includes/html-api/class-wp-html-processor.php</a></li>
<li><a href="#trunktestsphpunittestshtmlapiwpHtmlProcessorphp">trunk/tests/phpunit/tests/html-api/wpHtmlProcessor.php</a></li>
<li><a href="#trunktestsphpunittestshtmlapiwpHtmlProcessorBreadcrumbsphp">trunk/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php</a></li>
<li><a href="#trunktestsphpunittestshtmlapiwpHtmlProcessorSemanticRulesphp">trunk/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunktestsphpunittestshtmlapiwpHtmlProcessorSemanticRulesHeadingElementsphp">trunk/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRulesHeadingElements.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludeshtmlapiclasswphtmlopenelementsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/html-api/class-wp-html-open-elements.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/html-api/class-wp-html-open-elements.php    2023-12-13 17:48:09 UTC (rev 57185)
+++ trunk/src/wp-includes/html-api/class-wp-html-open-elements.php      2023-12-13 17:51:42 UTC (rev 57186)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -116,6 +116,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                return true;
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        if (
+                               '(internal: H1 through H6 - do not use)' === $tag_name &&
+                               in_array( $node->node_name, array( 'H1', 'H2', 'H3', 'H4', 'H5', 'H6' ), true )
+                       ) {
+                               return true;
+                       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                         switch ( $node->node_name ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                case 'HTML':
</span><span class="cx" style="display: block; padding: 0 10px">                                        return false;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -270,6 +277,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                foreach ( $this->walk_up() as $item ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->pop();
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        if (
+                               '(internal: H1 through H6 - do not use)' === $tag_name &&
+                               in_array( $item->node_name, array( 'H1', 'H2', 'H3', 'H4', 'H5', 'H6' ), true )
+                       ) {
+                               return true;
+                       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                         if ( $tag_name === $item->node_name ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                return true;
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span></span></pre></div>
<a id="trunksrcwpincludeshtmlapiclasswphtmlprocessorphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/html-api/class-wp-html-processor.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/html-api/class-wp-html-processor.php        2023-12-13 17:48:09 UTC (rev 57185)
+++ trunk/src/wp-includes/html-api/class-wp-html-processor.php  2023-12-13 17:51:42 UTC (rev 57186)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -102,7 +102,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">  *  - Containers: ADDRESS, BLOCKQUOTE, DETAILS, DIALOG, DIV, FOOTER, HEADER, MAIN, MENU, SPAN, SUMMARY.
</span><span class="cx" style="display: block; padding: 0 10px">  *  - Form elements: BUTTON, FIELDSET, SEARCH.
</span><span class="cx" style="display: block; padding: 0 10px">  *  - Formatting elements: B, BIG, CODE, EM, FONT, I, SMALL, STRIKE, STRONG, TT, U.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- *  - Heading elements: HGROUP.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ *  - Heading elements: H1, H2, H3, H4, H5, H6, HGROUP.
</ins><span class="cx" style="display: block; padding: 0 10px">  *  - Links: A.
</span><span class="cx" style="display: block; padding: 0 10px">  *  - Lists: DL.
</span><span class="cx" style="display: block; padding: 0 10px">  *  - Media elements: FIGCAPTION, FIGURE, IMG.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -698,6 +698,60 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                return true;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        /*
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         * > A start tag whose tag name is one of: "h1", "h2", "h3", "h4", "h5", "h6"
+                        */
+                       case '+H1':
+                       case '+H2':
+                       case '+H3':
+                       case '+H4':
+                       case '+H5':
+                       case '+H6':
+                               if ( $this->state->stack_of_open_elements->has_p_in_button_scope() ) {
+                                       $this->close_a_p_element();
+                               }
+
+                               if (
+                                       in_array(
+                                               $this->state->stack_of_open_elements->current_node()->node_name,
+                                               array( 'H1', 'H2', 'H3', 'H4', 'H5', 'H6' ),
+                                               true
+                                       )
+                               ) {
+                                       // @TODO: Indicate a parse error once it's possible.
+                                       $this->state->stack_of_open_elements->pop();
+                               }
+
+                               $this->insert_html_element( $this->state->current_token );
+                               return true;
+
+                       /*
+                        * > An end tag whose tag name is one of: "h1", "h2", "h3", "h4", "h5", "h6"
+                        */
+                       case '-H1':
+                       case '-H2':
+                       case '-H3':
+                       case '-H4':
+                       case '-H5':
+                       case '-H6':
+                               if ( ! $this->state->stack_of_open_elements->has_element_in_scope( '(internal: H1 through H6 - do not use)' ) ) {
+                                       /*
+                                        * This is a parse error; ignore the token.
+                                        *
+                                        * @TODO: Indicate a parse error once it's possible.
+                                        */
+                                       return $this->step();
+                               }
+
+                               $this->generate_implied_end_tags();
+
+                               if ( $this->state->stack_of_open_elements->current_node()->node_name !== $tag_name ) {
+                                       // @TODO: Record parse error: this error doesn't impact parsing.
+                               }
+
+                               $this->state->stack_of_open_elements->pop_until( '(internal: H1 through H6 - do not use)' );
+                               return true;
+
+                       /*
</ins><span class="cx" style="display: block; padding: 0 10px">                          * > An end tag whose tag name is "p"
</span><span class="cx" style="display: block; padding: 0 10px">                         */
</span><span class="cx" style="display: block; padding: 0 10px">                        case '-P':
</span></span></pre></div>
<a id="trunktestsphpunittestshtmlapiwpHtmlProcessorphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/html-api/wpHtmlProcessor.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/html-api/wpHtmlProcessor.php    2023-12-13 17:48:09 UTC (rev 57185)
+++ trunk/tests/phpunit/tests/html-api/wpHtmlProcessor.php      2023-12-13 17:51:42 UTC (rev 57186)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -91,8 +91,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @covers WP_HTML_Processor::next_tag
</span><span class="cx" style="display: block; padding: 0 10px">         * @covers WP_HTML_Processor::seek
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         *
-        * @throws WP_HTML_Unsupported_Exception
</del><span class="cx" style="display: block; padding: 0 10px">          */
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_clear_to_navigate_after_seeking() {
</span><span class="cx" style="display: block; padding: 0 10px">                $p = WP_HTML_Processor::create_fragment( '<div one><strong></strong></div><p><strong two></strong></p>' );
</span></span></pre></div>
<a id="trunktestsphpunittestshtmlapiwpHtmlProcessorBreadcrumbsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php 2023-12-13 17:48:09 UTC (rev 57185)
+++ trunk/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php   2023-12-13 17:51:42 UTC (rev 57186)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -56,6 +56,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'FIGURE',
</span><span class="cx" style="display: block; padding: 0 10px">                        'FONT',
</span><span class="cx" style="display: block; padding: 0 10px">                        'FOOTER',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        'H1',
+                       'H2',
+                       'H3',
+                       'H4',
+                       'H5',
+                       'H6',
</ins><span class="cx" style="display: block; padding: 0 10px">                         'HEADER',
</span><span class="cx" style="display: block; padding: 0 10px">                        'HGROUP',
</span><span class="cx" style="display: block; padding: 0 10px">                        'I',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -142,12 +148,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'FORM',
</span><span class="cx" style="display: block; padding: 0 10px">                        'FRAME',
</span><span class="cx" style="display: block; padding: 0 10px">                        'FRAMESET',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'H1',
-                       'H2',
-                       'H3',
-                       'H4',
-                       'H5',
-                       'H6',
</del><span class="cx" style="display: block; padding: 0 10px">                         'HEAD',
</span><span class="cx" style="display: block; padding: 0 10px">                        'HR',
</span><span class="cx" style="display: block; padding: 0 10px">                        'HTML',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -352,6 +352,14 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'MAIN inside MAIN inside SPAN'          => array( '<span><main><main target>', array( 'HTML', 'BODY', 'SPAN', 'MAIN', 'MAIN' ), 1 ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'MAIN next to unclosed P'               => array( '<p><main target>', array( 'HTML', 'BODY', 'MAIN' ), 1 ),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+                       // H1 - H6 close out _any_ H1 - H6 when encountering _any_ of H1 - H6, making this section surprising.
+                       'EM inside H3 after unclosed P'         => array( '<p><h3><em target>Important Message</em></h3>', array( 'HTML', 'BODY', 'H3', 'EM' ), 1 ),
+                       'H4 after H2'                           => array( '<h2>Major</h2><h4 target>Minor</h4>', array( 'HTML', 'BODY', 'H4' ), 1 ),
+                       'H4 after unclosed H2'                  => array( '<h2>Major<h4 target>Minor</h3>', array( 'HTML', 'BODY', 'H4' ), 1 ),
+                       'H4 inside H2'                          => array( '<h2><span>Major<h4 target>Minor</h3></span>', array( 'HTML', 'BODY', 'H2', 'SPAN', 'H4' ), 1 ),
+                       'H5 after unclosed H4 inside H2'        => array( '<h2><span>Major<h4>Minor</span></h3><h5 target>', array( 'HTML', 'BODY', 'H2', 'SPAN', 'H5' ), 1 ),
+                       'H5 after H4 inside H2'                 => array( '<h2><span>Major<h4>Minor</h4></span></h3><h5 target>', array( 'HTML', 'BODY', 'H5' ), 1 ),
</ins><span class="cx" style="display: block; padding: 0 10px">                 );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -387,29 +395,29 @@
</span><span class="cx" style="display: block; padding: 0 10px">        public function data_html_with_breadcrumbs_of_various_specificity() {
</span><span class="cx" style="display: block; padding: 0 10px">                return array(
</span><span class="cx" style="display: block; padding: 0 10px">                        // Test with void elements.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'Inner IMG'                      => array( '<div><span><figure><img target></figure></span></div>', array( 'span', 'figure', 'img' ), true ),
-                       'Inner IMG wildcard'             => array( '<div><span><figure><img target></figure></span></div>', array( 'span', '*', 'img' ), true ),
-                       'Inner IMG no wildcard'          => array( '<div><span><figure><img target></figure></span></div>', array( 'span', 'img' ), false ),
-                       'Full specification'             => array( '<div><span><figure><img target></figure></span></div>', array( 'html', 'body', 'div', 'span', 'figure', 'img' ), true ),
-                       'Invalid Full specification'     => array( '<div><span><figure><img target></figure></span></div>', array( 'html', 'div', 'span', 'figure', 'img' ), false ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'Inner IMG'                               => array( '<div><span><figure><img target></figure></span></div>', array( 'span', 'figure', 'img' ), true ),
+                       'Inner IMG wildcard'                      => array( '<div><span><figure><img target></figure></span></div>', array( 'span', '*', 'img' ), true ),
+                       'Inner IMG no wildcard'                   => array( '<div><span><figure><img target></figure></span></div>', array( 'span', 'img' ), false ),
+                       'Full specification'                      => array( '<div><span><figure><img target></figure></span></div>', array( 'html', 'body', 'div', 'span', 'figure', 'img' ), true ),
+                       'Invalid Full specification'              => array( '<div><span><figure><img target></figure></span></div>', array( 'html', 'div', 'span', 'figure', 'img' ), false ),
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        // Test also with non-void elements that open and close.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'Inner P'                        => array( '<div><span><figure><p target></figure></span></div>', array( 'span', 'figure', 'p' ), true ),
-                       'Inner P wildcard'               => array( '<div><span><figure><p target></figure></span></div>', array( 'span', '*', 'p' ), true ),
-                       'Inner P no wildcard'            => array( '<div><span><figure><p target></figure></span></div>', array( 'span', 'p' ), false ),
-                       'Full specification (P)'         => array( '<div><span><figure><p target></figure></span></div>', array( 'html', 'body', 'div', 'span', 'figure', 'p' ), true ),
-                       'Invalid Full specification (P)' => array( '<div><span><figure><p target></figure></span></div>', array( 'html', 'div', 'span', 'figure', 'p' ), false ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'Inner P'                                 => array( '<div><span><figure><p target></figure></span></div>', array( 'span', 'figure', 'p' ), true ),
+                       'Inner P wildcard'                        => array( '<div><span><figure><p target></figure></span></div>', array( 'span', '*', 'p' ), true ),
+                       'Inner P no wildcard'                     => array( '<div><span><figure><p target></figure></span></div>', array( 'span', 'p' ), false ),
+                       'Full specification (P)'                  => array( '<div><span><figure><p target></figure></span></div>', array( 'html', 'body', 'div', 'span', 'figure', 'p' ), true ),
+                       'Invalid Full specification (P)'          => array( '<div><span><figure><p target></figure></span></div>', array( 'html', 'div', 'span', 'figure', 'p' ), false ),
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        // Ensure that matches aren't on tag closers.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'Inner P'                        => array( '<div><span><figure></p target></figure></span></div>', array( 'span', 'figure', 'p' ), false ),
-                       'Inner P wildcard'               => array( '<div><span><figure></p target></figure></span></div>', array( 'span', '*', 'p' ), false ),
-                       'Inner P no wildcard'            => array( '<div><span><figure></p target></figure></span></div>', array( 'span', 'p' ), false ),
-                       'Full specification (P)'         => array( '<div><span><figure></p target></figure></span></div>', array( 'html', 'body', 'div', 'span', 'figure', 'p' ), false ),
-                       'Invalid Full specification (P)' => array( '<div><span><figure></p target></figure></span></div>', array( 'html', 'div', 'span', 'figure', 'p' ), false ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'Inner P (Closer)'                        => array( '<div><span><figure></p target></figure></span></div>', array( 'span', 'figure', 'p' ), false ),
+                       'Inner P wildcard (Closer)'               => array( '<div><span><figure></p target></figure></span></div>', array( 'span', '*', 'p' ), false ),
+                       'Inner P no wildcard (Closer)'            => array( '<div><span><figure></p target></figure></span></div>', array( 'span', 'p' ), false ),
+                       'Full specification (P) (Closer)'         => array( '<div><span><figure></p target></figure></span></div>', array( 'html', 'body', 'div', 'span', 'figure', 'p' ), false ),
+                       'Invalid Full specification (P) (Closer)' => array( '<div><span><figure></p target></figure></span></div>', array( 'html', 'div', 'span', 'figure', 'p' ), false ),
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        // Test wildcard behaviors.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'Single wildcard element'        => array( '<figure><code><div><p><span><img target></span></p></div></code></figure>', array( '*' ), true ),
-                       'Child of wildcard element'      => array( '<figure><code><div><p><span><img target></span></p></div></code></figure>', array( 'SPAN', '*' ), true ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'Single wildcard element'                 => array( '<figure><code><div><p><span><img target></span></p></div></code></figure>', array( '*' ), true ),
+                       'Child of wildcard element'               => array( '<figure><code><div><p><span><img target></span></p></div></code></figure>', array( 'SPAN', '*' ), true ),
</ins><span class="cx" style="display: block; padding: 0 10px">                 );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="trunktestsphpunittestshtmlapiwpHtmlProcessorSemanticRulesphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php       2023-12-13 17:48:09 UTC (rev 57185)
+++ trunk/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php 2023-12-13 17:51:42 UTC (rev 57186)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -120,10 +120,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * element in scope, that it skips the tag entirely.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 58961
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         *
-        * @since 6.4.0
-        *
-        * @throws Exception
</del><span class="cx" style="display: block; padding: 0 10px">          */
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_in_body_skips_unexpected_button_closer() {
</span><span class="cx" style="display: block; padding: 0 10px">                $p = WP_HTML_Processor::create_fragment( '<div>Test</button></div>' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -145,10 +141,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * Verifies insertion of a BUTTON element when no existing BUTTON is already in scope.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 58961
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         *
-        * @since 6.4.0
-        *
-        * @throws WP_HTML_Unsupported_Exception
</del><span class="cx" style="display: block; padding: 0 10px">          */
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_in_body_button_with_no_button_in_scope() {
</span><span class="cx" style="display: block; padding: 0 10px">                $p = WP_HTML_Processor::create_fragment( '<div><p>Click the button <button one>here</button>!</p></div><button two>not here</button>' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -174,8 +166,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 58961
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 6.4.0
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         *
-        * @throws WP_HTML_Unsupported_Exception
</del><span class="cx" style="display: block; padding: 0 10px">          */
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_in_body_button_with_button_in_scope_as_parent() {
</span><span class="cx" style="display: block; padding: 0 10px">                $p = WP_HTML_Processor::create_fragment( '<div><p>Click the button <button one>almost<button two>here</button>!</p></div><button three>not here</button>' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -209,8 +199,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 58961
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 6.4.0
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         *
-        * @throws WP_HTML_Unsupported_Exception
</del><span class="cx" style="display: block; padding: 0 10px">          */
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_in_body_button_with_button_in_scope_as_ancestor() {
</span><span class="cx" style="display: block; padding: 0 10px">                $p = WP_HTML_Processor::create_fragment( '<div><button one><p>Click the button <span><button two>here</button>!</span></p></div><button three>not here</button>' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -236,7 +224,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( array( 'HTML', 'BODY', 'BUTTON' ), $p->get_breadcrumbs(), 'Failed to produce expected DOM nesting for third button.' );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        /*
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * Verifies that when "in body" and encountering "any other end tag"
</span><span class="cx" style="display: block; padding: 0 10px">         * that the HTML processor ignores the end tag if there's a special
</span><span class="cx" style="display: block; padding: 0 10px">         * element on the stack of open elements before the matching opening.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -259,7 +247,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'SPAN', 'DIV' ), $p->get_breadcrumbs(), 'Failed to produce expected DOM nesting: SPAN should still be open and DIV should be its child.' );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        /*
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * Verifies that when "in body" and encountering "any other end tag"
</span><span class="cx" style="display: block; padding: 0 10px">         * that the HTML processor closes appropriate elements on the stack of
</span><span class="cx" style="display: block; padding: 0 10px">         * open elements up to the matching opening.
</span></span></pre></div>
<a id="trunktestsphpunittestshtmlapiwpHtmlProcessorSemanticRulesHeadingElementsphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRulesHeadingElements.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRulesHeadingElements.php                                (rev 0)
+++ trunk/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRulesHeadingElements.php  2023-12-13 17:51:42 UTC (rev 57186)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,126 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * Unit tests covering WP_HTML_Processor compliance with HTML5 semantic parsing rules
+ * for the H1 - H6 heading elements.
+ *
+ * @package WordPress
+ * @subpackage HTML-API
+ *
+ * @since 6.5.0
+ *
+ * @group html-api
+ *
+ * @coversDefaultClass WP_HTML_Processor
+ */
+class Tests_HtmlApi_WpHtmlProcessorSemanticRulesHeadingElements extends WP_UnitTestCase {
+       /*******************************************************************
+        * RULES FOR "IN BODY" MODE
+        *******************************************************************/
+
+       /**
+        * Verifies that H1 through H6 elements generate implied end tags.
+        *
+        * @ticket 60060
+        *
+        * @covers WP_HTML_Processor::step
+        *
+        * @dataProvider data_heading_elements
+        *
+        * @param string $tag_name Name of H1 - H6 element under test.
+        */
+       public function test_in_body_heading_element_closes_open_p_tag( $tag_name ) {
+               $processor = WP_HTML_Processor::create_fragment(
+                       "<p>Open<{$tag_name}>Closed P</{$tag_name}><img></p>"
+               );
+
+               $processor->next_tag( $tag_name );
+               $this->assertSame(
+                       array( 'HTML', 'BODY', $tag_name ),
+                       $processor->get_breadcrumbs(),
+                       "Expected {$tag_name} to be a direct child of the BODY, having closed the open P element."
+               );
+
+               $processor->next_tag( 'IMG' );
+               $this->assertSame(
+                       array( 'HTML', 'BODY', 'IMG' ),
+                       $processor->get_breadcrumbs(),
+                       'Expected IMG to be a direct child of BODY, having closed the open P element.'
+               );
+       }
+
+       /**
+        * Data provider.
+        *
+        * @return array[].
+        */
+       public function data_heading_elements() {
+               return array(
+                       'H1' => array( 'H1' ),
+                       'H2' => array( 'H2' ),
+                       'H3' => array( 'H3' ),
+                       'H4' => array( 'H4' ),
+                       'H5' => array( 'H5' ),
+                       'H6' => array( 'H5' ),
+               );
+       }
+
+       /**
+        * Verifies that H1 through H6 elements close an open H1 through H6 element.
+        *
+        * @ticket 60060
+        *
+        * @covers WP_HTML_Processor::step
+        *
+        * @dataProvider data_heading_combinations
+        *
+        * @param string $first_heading  H1 - H6 element appearing (unclosed) before the second.
+        * @param string $second_heading H1 - H6 element appearing after the first.
+        */
+       public function test_in_body_heading_element_closes_other_heading_elements( $first_heading, $second_heading ) {
+               $processor = WP_HTML_Processor::create_fragment(
+                       "<div><{$first_heading} first> then <{$second_heading} second> and end </{$second_heading}><img></{$first_heading}></div>"
+               );
+
+               while ( $processor->next_tag() && null === $processor->get_attribute( 'second' ) ) {
+                       continue;
+               }
+
+               $this->assertTrue(
+                       $processor->get_attribute( 'second' ),
+                       "Failed to find expected {$second_heading} tag."
+               );
+
+               $this->assertSame(
+                       array( 'HTML', 'BODY', 'DIV', $second_heading ),
+                       $processor->get_breadcrumbs(),
+                       "Expected {$second_heading} to be a direct child of the DIV, having closed the open {$first_heading} element."
+               );
+
+               $processor->next_tag( 'IMG' );
+               $this->assertSame(
+                       array( 'HTML', 'BODY', 'DIV', 'IMG' ),
+                       $processor->get_breadcrumbs(),
+                       "Expected IMG to be a direct child of DIV, having closed the open {$first_heading} element."
+               );
+       }
+
+       /**
+        * Data provider.
+        *
+        * @return array[]
+        */
+       public function data_heading_combinations() {
+               $headings = array( 'H1', 'H2', 'H3', 'H4', 'H5', 'H6' );
+
+               $combinations = array();
+
+               // Create all unique pairs of H1 - H6 elements.
+               foreach ( $headings as $first_tag ) {
+                       foreach ( $headings as $second_tag ) {
+                               $combinations[ "{$first_tag} then {$second_tag}" ] = array( $first_tag, $second_tag );
+                       }
+               }
+
+               return $combinations;
+       }
+}
</ins></span></pre>
</div>
</div>

</body>
</html>