Skip to content

Commit

Permalink
HTML API: Backport updates from Core (#56578)
Browse files Browse the repository at this point in the history
 - Fix typo in Tag Processor example comment.
 - Rewrite @todo comments.
 - Add support for new tags in HTML Processor:
    - ADDRESS, ARTICLE, ASIDE, CENTER, DETAILS, DIALOG,
    - DIR, DL, FIELDSET, FOOTER, HEADER, HGROUP, MAIN,
    - MENU, NAV, SEARCH, SECTION, SUMMARY
  • Loading branch information
dmsnell committed Nov 28, 2023
1 parent 53ffc0b commit 9d43d50
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
*
* Example:
*
* if ( $tags->next_tag( array( 'class' => 'wp-group-block' ) ) ) {
* if ( $tags->next_tag( array( 'class_name' => 'wp-group-block' ) ) ) {
* $tags->set_attribute( 'title', 'This groups the contained content.' );
* $tags->remove_attribute( 'data-test-id' );
* }
Expand Down Expand Up @@ -2031,8 +2031,8 @@ public function set_attribute( $name, $value ) {
*
* @see https://html.spec.whatwg.org/#attributes-2
*
* @TODO as the only regex pattern maybe we should take it out? are
* Unicode patterns available broadly in Core?
* @todo As the only regex pattern maybe we should take it out?
* Are Unicode patterns available broadly in Core?
*/
if ( preg_match(
'~[' .
Expand Down
56 changes: 48 additions & 8 deletions lib/compat/wordpress-6.4/html-api/class-wp-html-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,16 @@
*
* The following list specifies the HTML tags that _are_ supported:
*
* - Containers: ADDRESS, BLOCKQUOTE, DETAILS, DIALOG, DIV, FOOTER, HEADER, MAIN, MENU, SPAN, SUMMARY.
* - Form elements: BUTTON, FIELDSET, SEARCH.
* - Formatting elements: B, BIG, CODE, EM, FONT, I, SMALL, STRIKE, STRONG, TT, U.
* - Heading elements: HGROUP.
* - Links: A.
* - The formatting elements: B, BIG, CODE, EM, FONT, I, SMALL, STRIKE, STRONG, TT, U.
* - Containers: DIV, FIGCAPTION, FIGURE, SPAN.
* - Form elements: BUTTON.
* - Lists: DL.
* - Media elements: FIGCAPTION, FIGURE, IMG.
* - Paragraph: P.
* - Void elements: IMG.
* - Sectioning elements: ARTICLE, ASIDE, NAV, SECTION
* - Deprecated elements: CENTER, DIR
*
* ### Supported markup
*
Expand Down Expand Up @@ -346,7 +350,7 @@ public function get_last_error() {
/**
* Finds the next tag matching the $query.
*
* @TODO: Support matching the class name and tag name.
* @todo Support matching the class name and tag name.
*
* @since 6.4.0
*
Expand Down Expand Up @@ -555,9 +559,9 @@ public function step( $node_to_process = self::PROCESS_NEXT_NODE ) {
* Breadcrumbs start at the outermost parent and descend toward the matched element.
* They always include the entire path from the root HTML node to the matched element.
*
* @TODO: It could be more efficient to expose a generator-based version of this function
* to avoid creating the array copy on tag iteration. If this is done, it would likely
* be more useful to walk up the stack when yielding instead of starting at the top.
* @todo It could be more efficient to expose a generator-based version of this function
* to avoid creating the array copy on tag iteration. If this is done, it would likely
* be more useful to walk up the stack when yielding instead of starting at the top.
*
* Example
*
Expand Down Expand Up @@ -625,11 +629,29 @@ private function step_in_body() {
* > "fieldset", "figcaption", "figure", "footer", "header", "hgroup",
* > "main", "menu", "nav", "ol", "p", "search", "section", "summary", "ul"
*/
case '+ADDRESS':
case '+ARTICLE':
case '+ASIDE':
case '+BLOCKQUOTE':
case '+CENTER':
case '+DETAILS':
case '+DIALOG':
case '+DIR':
case '+DIV':
case '+DL':
case '+FIELDSET':
case '+FIGCAPTION':
case '+FIGURE':
case '+FOOTER':
case '+HEADER':
case '+HGROUP':
case '+MAIN':
case '+MENU':
case '+NAV':
case '+P':
case '+SEARCH':
case '+SECTION':
case '+SUMMARY':
if ( $this->state->stack_of_open_elements->has_p_in_button_scope() ) {
$this->close_a_p_element();
}
Expand All @@ -643,11 +665,29 @@ private function step_in_body() {
* > "figcaption", "figure", "footer", "header", "hgroup", "listing", "main",
* > "menu", "nav", "ol", "pre", "search", "section", "summary", "ul"
*/
case '-ADDRESS':
case '-ARTICLE':
case '-ASIDE':
case '-BLOCKQUOTE':
case '-BUTTON':
case '-CENTER':
case '-DETAILS':
case '-DIALOG':
case '-DIR':
case '-DIV':
case '-DL':
case '-FIELDSET':
case '-FIGCAPTION':
case '-FIGURE':
case '-FOOTER':
case '-HEADER':
case '-HGROUP':
case '-MAIN':
case '-MENU':
case '-NAV':
case '-SEARCH':
case '-SECTION':
case '-SUMMARY':
if ( ! $this->state->stack_of_open_elements->has_element_in_scope( $tag_name ) ) {
// @TODO: Report parse error.
// Ignore the token.
Expand Down

0 comments on commit 9d43d50

Please sign in to comment.