<!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>[58833] trunk: HTML API: Add TEMPLATE and related support in 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/58833">58833</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/58833","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>dmsnell</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2024-07-30 18:44:45 +0000 (Tue, 30 Jul 2024)</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 TEMPLATE and related support in HTML Processor.

As part of work to add more spec support to the HTML API, this patch adds
support for the IN TEMPLATE and IN HEAD insertion modes. These changes are
primarily about adding support for TEMPLATE elements in the HTML Processor,
but include support for other tags commonly found in the document head, such
as LINK, META, SCRIPT, STYLE, and TITLE.

Developed in https://github.com/wordpress/wordpress-develop/pull/7046
Discussed in https://core.trac.wordpress.org/ticket/61576

Props: dmsnell, jonsurrell, westonruter.
See <a href="https://core.trac.wordpress.org/ticket/61576">#61576</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="#trunktestsphpunittestshtmlapiwpHtmlProcessorBreadcrumbsphp">trunk/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php</a></li>
<li><a href="#trunktestsphpunittestshtmlapiwpHtmlProcessorHtml5libphp">trunk/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.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    2024-07-30 12:23:06 UTC (rev 58832)
+++ trunk/src/wp-includes/html-api/class-wp-html-open-elements.php      2024-07-30 18:44:45 UTC (rev 58833)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -308,7 +308,20 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'MARQUEE',
</span><span class="cx" style="display: block; padding: 0 10px">                                'OBJECT',
</span><span class="cx" style="display: block; padding: 0 10px">                                'TEMPLATE',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                // @todo: Support SVG and MathML nodes when support for foreign content is added.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+                               /*
+                                * @todo Support SVG and MathML nodes when support for foreign content is added.
+                                *
+                                * - MathML mi
+                                * - MathML mo
+                                * - MathML mn
+                                * - MathML ms
+                                * - MathML mtext
+                                * - MathML annotation-xml
+                                * - SVG foreignObject
+                                * - SVG desc
+                                * - SVG title
+                                */
</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">@@ -349,7 +362,20 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'OL',
</span><span class="cx" style="display: block; padding: 0 10px">                                'TEMPLATE',
</span><span class="cx" style="display: block; padding: 0 10px">                                'UL',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                // @todo: Support SVG and MathML nodes when support for foreign content is added.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+                               /*
+                                * @todo Support SVG and MathML nodes when support for foreign content is added.
+                                *
+                                * - MathML mi
+                                * - MathML mo
+                                * - MathML mn
+                                * - MathML ms
+                                * - MathML mtext
+                                * - MathML annotation-xml
+                                * - SVG foreignObject
+                                * - SVG desc
+                                * - SVG title
+                                */
</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">@@ -386,7 +412,20 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'MARQUEE',
</span><span class="cx" style="display: block; padding: 0 10px">                                'OBJECT',
</span><span class="cx" style="display: block; padding: 0 10px">                                'TEMPLATE',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                // @todo: Support SVG and MathML nodes when support for foreign content is added.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+                               /*
+                                * @todo Support SVG and MathML nodes when support for foreign content is added.
+                                *
+                                * - MathML mi
+                                * - MathML mo
+                                * - MathML mn
+                                * - MathML ms
+                                * - MathML mtext
+                                * - MathML annotation-xml
+                                * - SVG foreignObject
+                                * - SVG desc
+                                * - SVG title
+                                */
</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="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        2024-07-30 12:23:06 UTC (rev 58832)
+++ trunk/src/wp-includes/html-api/class-wp-html-processor.php  2024-07-30 18:44:45 UTC (rev 58833)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1040,7 +1040,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * This internal function performs the 'in head' insertion mode
</span><span class="cx" style="display: block; padding: 0 10px">         * logic for the generalized WP_HTML_Processor::step() function.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * @since 6.7.0 Stub implementation.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * @since 6.7.0
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><span class="cx" style="display: block; padding: 0 10px">         * @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1050,7 +1050,211 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @return bool Whether an element was found.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        private function step_in_head(): bool {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_IN_HEAD . ' state.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $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}";
+
+               /*
+                * > 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
+                */
+               if ( '#text' === $op ) {
+                       $text = $this->get_modifiable_text();
+                       if ( '' === $text ) {
+                               /*
+                                * If the text is empty after processing HTML entities and stripping
+                                * U+0000 NULL bytes then ignore the token.
+                                */
+                               return $this->step();
+                       }
+
+                       if ( strlen( $text ) === strspn( $text, " \t\n\f\r" ) ) {
+                               // Insert the character.
+                               $this->insert_html_element( $this->state->current_token );
+                               return true;
+                       }
+               }
+
+               switch ( $op ) {
+                       /*
+                        * > 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 one of: "base", "basefont", "bgsound", "link"
+                        */
+                       case '+BASE':
+                       case '+BASEFONT':
+                       case '+BGSOUND':
+                       case '+LINK':
+                               $this->insert_html_element( $this->state->current_token );
+                               return true;
+
+                       /*
+                        * > A start tag whose tag name is "meta"
+                        */
+                       case '+META':
+                               $this->insert_html_element( $this->state->current_token );
+
+                               /*
+                                * > If the active speculative HTML parser is null, then:
+                                * >   - If the element has a charset attribute, and getting an encoding from
+                                * >     its value results in an encoding, and the confidence is currently
+                                * >     tentative, then change the encoding to the resulting encoding.
+                                */
+                               $charset = $this->get_attribute( 'charset' );
+                               if ( is_string( $charset ) ) {
+                                       $this->bail( 'Cannot yet process META tags with charset to determine encoding.' );
+                               }
+
+                               /*
+                                * >   - Otherwise, if the element has an http-equiv attribute whose value is
+                                * >     an ASCII case-insensitive match for the string "Content-Type", and
+                                * >     the element has a content attribute, and applying the algorithm for
+                                * >     extracting a character encoding from a meta element to that attribute's
+                                * >     value returns an encoding, and the confidence is currently tentative,
+                                * >     then change the encoding to the extracted encoding.
+                                */
+                               $http_equiv = $this->get_attribute( 'http-equiv' );
+                               $content    = $this->get_attribute( 'content' );
+                               if (
+                                       is_string( $http_equiv ) &&
+                                       is_string( $content ) &&
+                                       0 === strcasecmp( $http_equiv, 'Content-Type' )
+                               ) {
+                                       $this->bail( 'Cannot yet process META tags with http-equiv Content-Type to determine encoding.' );
+                               }
+
+                               return true;
+
+                       /*
+                        * > A start tag whose tag name is "title"
+                        */
+                       case '+TITLE':
+                               $this->insert_html_element( $this->state->current_token );
+                               return true;
+
+                       /*
+                        * > A start tag whose tag name is "noscript", if the scripting flag is enabled
+                        * > A start tag whose tag name is one of: "noframes", "style"
+                        *
+                        * The scripting flag is never enabled in this parser.
+                        */
+                       case '+NOFRAMES':
+                       case '+STYLE':
+                               $this->insert_html_element( $this->state->current_token );
+                               return true;
+
+                       /*
+                        * > A start tag whose tag name is "noscript", if the scripting flag is disabled
+                        */
+                       case '+NOSCRIPT':
+                               $this->insert_html_element( $this->state->current_token );
+                               $this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_IN_HEAD_NOSCRIPT;
+                               return true;
+
+                       /*
+                        * > A start tag whose tag name is "script"
+                        *
+                        * @todo Could the adjusted insertion location be anything other than the current location?
+                        */
+                       case '+SCRIPT':
+                               $this->insert_html_element( $this->state->current_token );
+                               return true;
+
+                       /*
+                        * > An end tag whose tag name is "head"
+                        */
+                       case '-HEAD':
+                               $this->state->stack_of_open_elements->pop();
+                               $this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_AFTER_HEAD;
+                               return true;
+
+                       /*
+                        * > An end tag whose tag name is one of: "body", "html", "br"
+                        */
+                       case '-BODY':
+                       case '-HTML':
+                       case '-BR':
+                               /*
+                                * > Act as described in the "anything else" entry below.
+                                */
+                               goto in_head_anything_else;
+                               break;
+
+                       /*
+                        * > A start tag whose tag name is "template"
+                        *
+                        * @todo Could the adjusted insertion location be anything other than the current location?
+                        */
+                       case '+TEMPLATE':
+                               $this->state->active_formatting_elements->insert_marker();
+                               $this->state->frameset_ok = false;
+
+                               $this->state->insertion_mode                      = WP_HTML_Processor_State::INSERTION_MODE_IN_TEMPLATE;
+                               $this->state->stack_of_template_insertion_modes[] = WP_HTML_Processor_State::INSERTION_MODE_IN_TEMPLATE;
+
+                               $this->insert_html_element( $this->state->current_token );
+                               return true;
+
+                       /*
+                        * > An end tag whose tag name is "template"
+                        */
+                       case '-TEMPLATE':
+                               if ( ! $this->state->stack_of_open_elements->contains( 'TEMPLATE' ) ) {
+                                       // @todo Indicate a parse error once it's possible.
+                                       return $this->step();
+                               }
+
+                               $this->generate_implied_end_tags_thoroughly();
+                               if ( ! $this->state->stack_of_open_elements->current_node_is( 'TEMPLATE' ) ) {
+                                       // @todo Indicate a parse error once it's possible.
+                               }
+
+                               $this->state->stack_of_open_elements->pop_until( 'TEMPLATE' );
+                               $this->state->active_formatting_elements->clear_up_to_last_marker();
+                               array_pop( $this->state->stack_of_template_insertion_modes );
+                               $this->reset_insertion_mode();
+                               return true;
+               }
+
+               /*
+                * > 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
+                */
+               in_head_anything_else:
+               $this->state->stack_of_open_elements->pop();
+               $this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_AFTER_HEAD;
+               return $this->step( self::REPROCESS_CURRENT_NODE );
</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">@@ -2991,7 +3195,117 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @return bool Whether an element was found.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        private function step_in_template(): bool {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_IN_TEMPLATE . ' state.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $token_name = $this->get_token_name();
+               $token_type = $this->get_token_type();
+               $is_closer  = $this->is_tag_closer();
+               $op_sigil   = '#tag' === $token_type ? ( $is_closer ? '-' : '+' ) : '';
+               $op         = "{$op_sigil}{$token_name}";
+
+               switch ( $op ) {
+                       /*
+                        * > A character token
+                        * > A comment token
+                        * > A DOCTYPE token
+                        */
+                       case '#text':
+                       case '#comment':
+                       case '#funky-comment':
+                       case '#presumptuous-tag':
+                       case 'html':
+                               return $this->step_in_body();
+
+                       /*
+                        * > A start tag whose tag name is one of: "base", "basefont", "bgsound", "link",
+                        * > "meta", "noframes", "script", "style", "template", "title"
+                        * > An end tag whose tag name is "template"
+                        */
+                       case '+BASE':
+                       case '+BASEFONT':
+                       case '+BGSOUND':
+                       case '+LINK':
+                       case '+META':
+                       case '+NOFRAMES':
+                       case '+SCRIPT':
+                       case '+STYLE':
+                       case '+TEMPLATE':
+                       case '+TITLE':
+                       case '-TEMPLATE':
+                               return $this->step_in_head();
+
+                       /*
+                        * > A start tag whose tag name is one of: "caption", "colgroup", "tbody", "tfoot", "thead"
+                        */
+                       case '+CAPTION':
+                       case '+COLGROUP':
+                       case '+TBODY':
+                       case '+TFOOT':
+                       case '+THEAD':
+                               array_pop( $this->state->stack_of_template_insertion_modes );
+                               $this->state->stack_of_template_insertion_modes[] = WP_HTML_Processor_State::INSERTION_MODE_IN_TABLE;
+                               $this->state->insertion_mode                      = WP_HTML_Processor_State::INSERTION_MODE_IN_TABLE;
+                               return $this->step( self::REPROCESS_CURRENT_NODE );
+
+                       /*
+                        * > A start tag whose tag name is "col"
+                        */
+                       case '+COL':
+                               array_pop( $this->state->stack_of_template_insertion_modes );
+                               $this->state->stack_of_template_insertion_modes[] = WP_HTML_Processor_State::INSERTION_MODE_IN_COLUMN_GROUP;
+                               $this->state->insertion_mode                      = WP_HTML_Processor_State::INSERTION_MODE_IN_COLUMN_GROUP;
+                               return $this->step( self::REPROCESS_CURRENT_NODE );
+
+                       /*
+                        * > A start tag whose tag name is "tr"
+                        */
+                       case '+TR':
+                               array_pop( $this->state->stack_of_template_insertion_modes );
+                               $this->state->stack_of_template_insertion_modes[] = WP_HTML_Processor_State::INSERTION_MODE_IN_TABLE_BODY;
+                               $this->state->insertion_mode                      = WP_HTML_Processor_State::INSERTION_MODE_IN_TABLE_BODY;
+                               return $this->step( self::REPROCESS_CURRENT_NODE );
+
+                       /*
+                        * > A start tag whose tag name is one of: "td", "th"
+                        */
+                       case '+TD':
+                       case '+TH':
+                               array_pop( $this->state->stack_of_template_insertion_modes );
+                               $this->state->stack_of_template_insertion_modes[] = WP_HTML_Processor_State::INSERTION_MODE_IN_ROW;
+                               $this->state->insertion_mode                      = WP_HTML_Processor_State::INSERTION_MODE_IN_ROW;
+                               return $this->step( self::REPROCESS_CURRENT_NODE );
+               }
+
+               /*
+                * > Any other start tag
+                */
+               if ( ! $is_closer ) {
+                       array_pop( $this->state->stack_of_template_insertion_modes );
+                       $this->state->stack_of_template_insertion_modes[] = WP_HTML_Processor_State::INSERTION_MODE_IN_BODY;
+                       $this->state->insertion_mode                      = WP_HTML_Processor_State::INSERTION_MODE_IN_BODY;
+                       return $this->step( self::REPROCESS_CURRENT_NODE );
+               }
+
+               /*
+                * > Any other end tag
+                */
+               if ( $is_closer ) {
+                       // Parse error: ignore the token.
+                       return $this->step();
+               }
+
+               /*
+                * > An end-of-file token
+                */
+               if ( ! $this->state->stack_of_open_elements->contains( 'TEMPLATE' ) ) {
+                       // Stop parsing.
+                       return false;
+               }
+
+               // @todo Indicate a parse error once it's possible.
+               $this->state->stack_of_open_elements->pop_until( 'TEMPLATE' );
+               $this->state->active_formatting_elements->clear_up_to_last_marker();
+               array_pop( $this->state->stack_of_template_insertion_modes );
+               $this->reset_insertion_mode();
+               return $this->step( self::REPROCESS_CURRENT_NODE );
</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="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 2024-07-30 12:23:06 UTC (rev 58832)
+++ trunk/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php   2024-07-30 18:44:45 UTC (rev 58833)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -46,8 +46,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'ASIDE',
</span><span class="cx" style="display: block; padding: 0 10px">                        'AUDIO',
</span><span class="cx" style="display: block; padding: 0 10px">                        'B',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        'BASE',
</ins><span class="cx" style="display: block; padding: 0 10px">                         'BDI',
</span><span class="cx" style="display: block; padding: 0 10px">                        'BDO',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        'BGSOUND', // Deprectated.
</ins><span class="cx" style="display: block; padding: 0 10px">                         'BIG',
</span><span class="cx" style="display: block; padding: 0 10px">                        'BLINK', // Deprecated.
</span><span class="cx" style="display: block; padding: 0 10px">                        'BR',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -93,6 +95,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'KEYGEN', // Deprecated.
</span><span class="cx" style="display: block; padding: 0 10px">                        'LABEL',
</span><span class="cx" style="display: block; padding: 0 10px">                        'LEGEND',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        'LINK',
</ins><span class="cx" style="display: block; padding: 0 10px">                         'LISTING', // Deprecated.
</span><span class="cx" style="display: block; padding: 0 10px">                        'MAIN',
</span><span class="cx" style="display: block; padding: 0 10px">                        'MAP',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -99,6 +102,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'MARK',
</span><span class="cx" style="display: block; padding: 0 10px">                        'MARQUEE', // Deprecated.
</span><span class="cx" style="display: block; padding: 0 10px">                        'MENU',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        'META',
</ins><span class="cx" style="display: block; padding: 0 10px">                         'METER',
</span><span class="cx" style="display: block; padding: 0 10px">                        'MULTICOL', // Deprecated.
</span><span class="cx" style="display: block; padding: 0 10px">                        'NAV',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -178,8 +182,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public static function data_unsupported_elements() {
</span><span class="cx" style="display: block; padding: 0 10px">                $unsupported_elements = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'BASE',
-                       'BGSOUND', // Deprecated; self-closing if self-closing flag provided, otherwise normal.
</del><span class="cx" style="display: block; padding: 0 10px">                         'BODY',
</span><span class="cx" style="display: block; padding: 0 10px">                        'FRAME',
</span><span class="cx" style="display: block; padding: 0 10px">                        'FRAMESET',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -186,9 +188,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'HEAD',
</span><span class="cx" style="display: block; padding: 0 10px">                        'HTML',
</span><span class="cx" style="display: block; padding: 0 10px">                        'IFRAME',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'LINK',
</del><span class="cx" style="display: block; padding: 0 10px">                         'MATH',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'META',
</del><span class="cx" style="display: block; padding: 0 10px">                         'NOEMBED', // Neutralized.
</span><span class="cx" style="display: block; padding: 0 10px">                        'NOFRAMES', // Neutralized.
</span><span class="cx" style="display: block; padding: 0 10px">                        'PLAINTEXT', // Neutralized.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -195,7 +195,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'SCRIPT',
</span><span class="cx" style="display: block; padding: 0 10px">                        'STYLE',
</span><span class="cx" style="display: block; padding: 0 10px">                        'SVG',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'TEMPLATE',
</del><span class="cx" style="display: block; padding: 0 10px">                         'TEXTAREA',
</span><span class="cx" style="display: block; padding: 0 10px">                        'TITLE',
</span><span class="cx" style="display: block; padding: 0 10px">                        'XMP', // Deprecated, use PRE instead.
</span></span></pre></div>
<a id="trunktestsphpunittestshtmlapiwpHtmlProcessorHtml5libphp"></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/wpHtmlProcessorHtml5lib.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php    2024-07-30 12:23:06 UTC (rev 58832)
+++ trunk/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php      2024-07-30 18:44:45 UTC (rev 58833)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -34,6 +34,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                'adoption01/line0046' => 'Unimplemented: Reconstruction of active formatting elements.',
</span><span class="cx" style="display: block; padding: 0 10px">                'adoption01/line0159' => 'Unimplemented: Reconstruction of active formatting elements.',
</span><span class="cx" style="display: block; padding: 0 10px">                'adoption01/line0318' => 'Unimplemented: Reconstruction of active formatting elements.',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                'template/line0885'   => 'Unimplemented: no parsing of attributes on context node.',
</ins><span class="cx" style="display: block; padding: 0 10px">                 'tests1/line0720'     => 'Unimplemented: Reconstruction of active formatting elements.',
</span><span class="cx" style="display: block; padding: 0 10px">                'tests15/line0001'    => 'Unimplemented: Reconstruction of active formatting elements.',
</span><span class="cx" style="display: block; padding: 0 10px">                'tests15/line0022'    => 'Unimplemented: Reconstruction of active formatting elements.',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -163,25 +164,34 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                return null;
</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">-                        if ( $was_text && '#text' !== $processor->get_token_name() ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $token_name = $processor->get_token_name();
+                       $token_type = $processor->get_token_type();
+                       $is_closer  = $processor->is_tag_closer();
+
+                       if ( $was_text && '#text' !== $token_name ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                 $output   .= "{$text_node}\"\n";
</span><span class="cx" style="display: block; padding: 0 10px">                                $was_text  = false;
</span><span class="cx" style="display: block; padding: 0 10px">                                $text_node = '';
</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">-                        switch ( $processor->get_token_type() ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 switch ( $token_type ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                 case '#tag':
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        $tag_name = strtolower( $processor->get_tag() );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 $tag_name = strtolower( $token_name );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        if ( $processor->is_tag_closer() ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 if ( $is_closer ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 --$indent_level;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+                                               if ( 'TEMPLATE' === $token_name ) {
+                                                       --$indent_level;
+                                               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 break;
</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">-                                        $tag_indent = count( $processor->get_breadcrumbs() ) - 1;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 $tag_indent = $indent_level;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                                        if ( ! WP_HTML_Processor::is_void( $tag_name ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                $indent_level = $tag_indent + 1;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                         ++$indent_level;
</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">                                        $output .= str_repeat( $indent, $tag_indent ) . "<{$tag_name}>\n";
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -209,6 +219,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                                $output .= str_repeat( $indent, $indent_level ) . "\"{$modifiable_text}\"\n";
</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 ( 'TEMPLATE' === $token_name ) {
+                                               $output .= str_repeat( $indent, $indent_level ) . "content\n";
+                                               ++$indent_level;
+                                       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                                         if ( ! $processor->is_void( $tag_name ) && ! $processor->expects_closer() ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                                --$indent_level;
</span><span class="cx" style="display: block; padding: 0 10px">                                        }
</span></span></pre>
</div>
</div>

</body>
</html>