Make WordPress Core


Ignore:
Timestamp:
08/10/2023 08:35:55 AM (12 months ago)
Author:
Bernhard Reiter
Message:

HTML API: Add support for BUTTON element.

This patch adds support to process the BUTTON element. This requires adding some additional semantic rules to handle situations where a BUTTON element is already in scope.

Also included is a fixup to enforce that WP_HTML_Processor::next_tag() never returns for a tag closer. This is useful with the Tag Processor, but not for the HTML Processor. There were tests relying on this behavior to assert that internal processes were working as they should, but those tests have been updated to use the semi-private step() function, which does stop on tag closers.

This patch is one in a series of changes to expand support within the HTML API, moving gradually to allow for more focused changes that are easier to review and test. The HTML Processor is a work in progress with a certain set of features slated to be ready and tested by 6.4.0, but it will only contain partial support of the HTML5 specification even after that. Whenever it cannot positively recognize and process its input it bails, and certain function stubs and logical stubs exist to structure future expansions of support.

Props dmsnell.
Fixes #58961.

File:
1 edited

Legend:

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

    r56363 r56380  
    114114        foreach ( $this->walk_up() as $node ) {
    115115            if ( $node->node_name === $tag_name ) {
     116                return true;
     117            }
     118
     119            switch ( $node->node_name ) {
     120                case 'HTML':
     121                    return false;
     122            }
     123
     124            if ( in_array( $node->node_name, $termination_list, true ) ) {
    116125                return true;
    117126            }
     
    176185     */
    177186    public function has_element_in_button_scope( $tag_name ) {
    178         return $this->has_element_in_specific_scope(
    179             $tag_name,
    180             array(
    181 
    182                 /*
    183                  * Because it's not currently possible to encounter
    184                  * one of the termination elements, they don't need
    185                  * to be listed here. If they were, they would be
    186                  * unreachable and only waste CPU cycles while
    187                  * scanning through HTML.
    188                  */
    189             )
    190         );
     187        return $this->has_element_in_specific_scope( $tag_name, array( 'BUTTON' ) );
    191188    }
    192189
     
    395392         */
    396393        switch ( $item->node_name ) {
     394            case 'BUTTON':
     395                $this->has_p_in_button_scope = false;
     396                break;
     397
    397398            case 'P':
    398399                $this->has_p_in_button_scope = true;
     
    420421         */
    421422        switch ( $item->node_name ) {
     423            case 'BUTTON':
     424                $this->has_p_in_button_scope = $this->has_element_in_button_scope( 'P' );
     425                break;
     426
    422427            case 'P':
    423428                $this->has_p_in_button_scope = $this->has_element_in_button_scope( 'P' );
Note: See TracChangeset for help on using the changeset viewer.