Make WordPress Core

Changeset 58839


Ignore:
Timestamp:
08/01/2024 10:04:44 PM (8 months ago)
Author:
dmsnell
Message:

HTML API: Add support for IN COLUMN GROUP parsing.

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

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

    r58836 r58839  
    30693069     * logic for the generalized WP_HTML_Processor::step() function.
    30703070     *
    3071      * @since 6.7.0 Stub implementation.
     3071     * @since 6.7.0
    30723072     *
    30733073     * @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
     
    30793079     */
    30803080    private function step_in_column_group(): bool {
    3081         $this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_IN_COLUMN_GROUP . ' state.' );
     3081        $token_name = $this->get_token_name();
     3082        $token_type = $this->get_token_type();
     3083        $op_sigil   = '#tag' === $token_type ? ( parent::is_tag_closer() ? '-' : '+' ) : '';
     3084        $op         = "{$op_sigil}{$token_name}";
     3085
     3086        switch ( $op ) {
     3087            /*
     3088             * > A character token that is one of U+0009 CHARACTER TABULATION, U+000A LINE FEED (LF),
     3089             * > U+000C FORM FEED (FF), U+000D CARRIAGE RETURN (CR), or U+0020 SPACE
     3090             */
     3091            case '#text':
     3092                $text = $this->get_modifiable_text();
     3093                if ( '' === $text ) {
     3094                    /*
     3095                     * If the text is empty after processing HTML entities and stripping
     3096                     * U+0000 NULL bytes then ignore the token.
     3097                     */
     3098                    return $this->step();
     3099                }
     3100
     3101                if ( strlen( $text ) === strspn( $text, " \t\n\f\r" ) ) {
     3102                    // Insert the character.
     3103                    $this->insert_html_element( $this->state->current_token );
     3104                    return true;
     3105                }
     3106
     3107                goto in_column_group_anything_else;
     3108                break;
     3109
     3110            /*
     3111             * > A comment token
     3112             */
     3113            case '#comment':
     3114            case '#funky-comment':
     3115            case '#presumptuous-tag':
     3116                $this->insert_html_element( $this->state->current_token );
     3117                return true;
     3118
     3119            /*
     3120             * > A DOCTYPE token
     3121             */
     3122            case 'html':
     3123                // @todo Indicate a parse error once it's possible.
     3124                return $this->step();
     3125
     3126            /*
     3127             * > A start tag whose tag name is "html"
     3128             */
     3129            case '+HTML':
     3130                return $this->step_in_body();
     3131
     3132            /*
     3133             * > A start tag whose tag name is "col"
     3134             */
     3135            case '+COL':
     3136                $this->insert_html_element( $this->state->current_token );
     3137                $this->state->stack_of_open_elements->pop();
     3138                return true;
     3139
     3140            /*
     3141             * > An end tag whose tag name is "colgroup"
     3142             */
     3143            case '-COLGROUP':
     3144                if ( ! $this->state->stack_of_open_elements->current_node_is( 'COLGROUP' ) ) {
     3145                    // @todo Indicate a parse error once it's possible.
     3146                    return $this->step();
     3147                }
     3148                $this->state->stack_of_open_elements->pop();
     3149                $this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_IN_TABLE;
     3150                return true;
     3151
     3152            /*
     3153             * > An end tag whose tag name is "col"
     3154             */
     3155            case '-COL':
     3156                // Parse error: ignore the token.
     3157                return $this->step();
     3158
     3159            /*
     3160             * > A start tag whose tag name is "template"
     3161             * > An end tag whose tag name is "template"
     3162             */
     3163            case '+TEMPLATE':
     3164            case '-TEMPLATE':
     3165                return $this->step_in_head();
     3166        }
     3167
     3168        in_column_group_anything_else:
     3169        /*
     3170         * > Anything else
     3171         */
     3172        if ( ! $this->state->stack_of_open_elements->current_node_is( 'COLGROUP' ) ) {
     3173            // @todo Indicate a parse error once it's possible.
     3174            return $this->step();
     3175        }
     3176        $this->state->stack_of_open_elements->pop();
     3177        $this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_IN_TABLE;
     3178        return $this->step( self::REPROCESS_CURRENT_NODE );
    30823179    }
    30833180
Note: See TracChangeset for help on using the changeset viewer.