Make WordPress Core

Changeset 58841


Ignore:
Timestamp:
08/01/2024 10:51:11 PM (2 years ago)
Author:
dmsnell
Message:

HTML API: Add support for IN SELECT IN TABLE parsing.

As part of work to add more spec support to the HTML API, this patch adds
support for the IN SELECT IN TABLE insertion mode. This small section of the
spec handles rules for the <select> element and its children when found
inside of a <table>.

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

Props: dmsnell, jonsurrell.
See #61576.

File:
1 edited

Legend:

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

    r58840 r58841  
    37723772         * logic for the generalized WP_HTML_Processor::step() function.
    37733773         *
    3774          * @since 6.7.0 Stub implementation.
     3774         * @since 6.7.0
    37753775         *
    37763776         * @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
     
    37823782         */
    37833783        private function step_in_select_in_table(): bool {
    3784                 $this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_IN_SELECT_IN_TABLE . ' state.' );
     3784                $token_name = $this->get_token_name();
     3785                $token_type = $this->get_token_type();
     3786                $op_sigil   = '#tag' === $token_type ? ( parent::is_tag_closer() ? '-' : '+' ) : '';
     3787                $op         = "{$op_sigil}{$token_name}";
     3788
     3789                switch ( $op ) {
     3790                        /*
     3791                         * > A start tag whose tag name is one of: "caption", "table", "tbody", "tfoot", "thead", "tr", "td", "th"
     3792                         */
     3793                        case '+CAPTION':
     3794                        case '+TABLE':
     3795                        case '+TBODY':
     3796                        case '+TFOOT':
     3797                        case '+THEAD':
     3798                        case '+TR':
     3799                        case '+TD':
     3800                        case '+TH':
     3801                                // @todo Indicate a parse error once it's possible.
     3802                                $this->state->stack_of_open_elements->pop_until( 'SELECT' );
     3803                                $this->reset_insertion_mode();
     3804                                return $this->step( self::REPROCESS_CURRENT_NODE );
     3805
     3806                        /*
     3807                         * > An end tag whose tag name is one of: "caption", "table", "tbody", "tfoot", "thead", "tr", "td", "th"
     3808                         */
     3809                        case '-CAPTION':
     3810                        case '-TABLE':
     3811                        case '-TBODY':
     3812                        case '-TFOOT':
     3813                        case '-THEAD':
     3814                        case '-TR':
     3815                        case '-TD':
     3816                        case '-TH':
     3817                                // @todo Indicate a parse error once it's possible.
     3818                                if ( ! $this->state->stack_of_open_elements->has_element_in_table_scope( $token_name ) ) {
     3819                                        return $this->step();
     3820                                }
     3821                                $this->state->stack_of_open_elements->pop_until( 'SELECT' );
     3822                                $this->reset_insertion_mode();
     3823                                return $this->step( self::REPROCESS_CURRENT_NODE );
     3824                }
     3825
     3826                /*
     3827                 * > Anything else
     3828                 */
     3829                return $this->step_in_select();
    37853830        }
    37863831
Note: See TracChangeset for help on using the changeset viewer.