Make WordPress Core


Ignore:
Timestamp:
12/13/2023 05:51:42 PM (3 years ago)
Author:
Bernhard Reiter
Message:

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 #60060.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/html-api/class-wp-html-open-elements.php

    r56753 r57186  
    114114                foreach ( $this->walk_up() as $node ) {
    115115                        if ( $node->node_name === $tag_name ) {
     116                                return true;
     117                        }
     118
     119                        if (
     120                                '(internal: H1 through H6 - do not use)' === $tag_name &&
     121                                in_array( $node->node_name, array( 'H1', 'H2', 'H3', 'H4', 'H5', 'H6' ), true )
     122                        ) {
    116123                                return true;
    117124                        }
     
    271278                        $this->pop();
    272279
     280                        if (
     281                                '(internal: H1 through H6 - do not use)' === $tag_name &&
     282                                in_array( $item->node_name, array( 'H1', 'H2', 'H3', 'H4', 'H5', 'H6' ), true )
     283                        ) {
     284                                return true;
     285                        }
     286
    273287                        if ( $tag_name === $item->node_name ) {
    274288                                return true;
Note: See TracChangeset for help on using the changeset viewer.