Make WordPress Core

Changeset 58840


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

HTML API: Add support for IN CAPTION parsing.

As part of work to add more spec support to the HTML API, this patch adds
support for the IN CAPTION insertion mode. This small section of the
spec handles rules for the <caption> element.

Developed in https://github.com/wordpress/wordpress-develop/pull/7041
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

    r58839 r58840  
    30503050         * logic for the generalized WP_HTML_Processor::step() function.
    30513051         *
    3052          * @since 6.7.0 Stub implementation.
     3052         * @since 6.7.0
    30533053         *
    30543054         * @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
     
    30603060         */
    30613061        private function step_in_caption(): bool {
    3062                 $this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_IN_CAPTION . ' state.' );
     3062                $tag_name = $this->get_tag();
     3063                $op_sigil = $this->is_tag_closer() ? '-' : '+';
     3064                $op       = "{$op_sigil}{$tag_name}";
     3065
     3066                switch ( $op ) {
     3067                        /*
     3068                         * > An end tag whose tag name is "caption"
     3069                         * > A start tag whose tag name is one of: "caption", "col", "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"
     3070                         * > An end tag whose tag name is "table"
     3071                         *
     3072                         * These tag handling rules are identical except for the final instruction.
     3073                         * Handle them in a single block.
     3074                         */
     3075                        case '-CAPTION':
     3076                        case '+CAPTION':
     3077                        case '+COL':
     3078                        case '+COLGROUP':
     3079                        case '+TBODY':
     3080                        case '+TD':
     3081                        case '+TFOOT':
     3082                        case '+TH':
     3083                        case '+THEAD':
     3084                        case '+TR':
     3085                        case '-TABLE':
     3086                                if ( ! $this->state->stack_of_open_elements->has_element_in_table_scope( 'CAPTION' ) ) {
     3087                                        // Parse error: ignore the token.
     3088                                        return $this->step();
     3089                                }
     3090
     3091                                $this->generate_implied_end_tags();
     3092                                if ( ! $this->state->stack_of_open_elements->current_node_is( 'CAPTION' ) ) {
     3093                                        // @todo Indicate a parse error once it's possible.
     3094                                }
     3095
     3096                                $this->state->stack_of_open_elements->pop_until( 'CAPTION' );
     3097                                $this->state->active_formatting_elements->clear_up_to_last_marker();
     3098                                $this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_IN_TABLE;
     3099
     3100                                // If this is not a CAPTION end tag, the token should be reprocessed.
     3101                                if ( '-CAPTION' === $op ) {
     3102                                        return true;
     3103                                }
     3104                                return $this->step( self::REPROCESS_CURRENT_NODE );
     3105
     3106                        /**
     3107                         * > An end tag whose tag name is one of: "body", "col", "colgroup", "html", "tbody", "td", "tfoot", "th", "thead", "tr"
     3108                         */
     3109                        case '-BODY':
     3110                        case '-COL':
     3111                        case '-COLGROUP':
     3112                        case '-HTML':
     3113                        case '-TBODY':
     3114                        case '-TD':
     3115                        case '-TFOOT':
     3116                        case '-TH':
     3117                        case '-THEAD':
     3118                        case '-TR':
     3119                                // Parse error: ignore the token.
     3120                                return $this->step();
     3121                }
     3122
     3123                /**
     3124                 * > Anything else
     3125                 * >   Process the token using the rules for the "in body" insertion mode.
     3126                 */
     3127                return $this->step_in_body();
    30633128        }
    30643129
Note: See TracChangeset for help on using the changeset viewer.