Make WordPress Core

Changeset 56331


Ignore:
Timestamp:
08/01/2023 07:54:54 AM (16 months ago)
Author:
Bernhard Reiter
Message:

HTML API: Add support for SPAN element.

In this patch we're introducing support for the SPAN element, which is the first
in the class of "any other tag" in the "in body" insertion mode.

This patch introduces the mechanisms required to handle that class of tags but
only introduces SPAN to keep the change focused. With the tests and mechanisms
in place it will be possible to follow-up and add another limited set of tags.

It's important that this not use the default catch-all in the switch handling
step_in_body because that would catch tags that have specific rules in previous
case statements that aren't yet added. For example, we don't want to treat the
TABLE element as "any other tag".

Props dmsnell.
Fixes #58907.

Location:
trunk
Files:
2 added
2 edited

Legend:

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

    r56274 r56331  
    627627                return true;
    628628
     629            /*
     630             * > Any other start tag
     631             */
     632            case '+SPAN':
     633                $this->reconstruct_active_formatting_elements();
     634                $this->insert_html_element( $this->current_token );
     635                return true;
     636
     637            /*
     638             * Any other end tag
     639             */
     640            case '-SPAN':
     641                foreach ( $this->state->stack_of_open_elements->walk_up() as $item ) {
     642                    // > If node is an HTML element with the same tag name as the token, then:
     643                    if ( $item->node_name === $tag_name ) {
     644                        $this->generate_implied_end_tags( $tag_name );
     645
     646                        // > If node is not the current node, then this is a parse error.
     647
     648                        $this->state->stack_of_open_elements->pop_until( $tag_name );
     649                        return true;
     650                    }
     651
     652                    // > Otherwise, if node is in the special category, then this is a parse error; ignore the token, and return.
     653                    if ( self::is_special( $item->node_name ) ) {
     654                        return $this->step();
     655                    }
     656                }
     657                // Execution should not reach here; if it does then something went wrong.
     658                return false;
     659
    629660            default:
    630661                $this->last_error = self::ERROR_UNSUPPORTED;
     
    874905     * @since 6.4.0
    875906     *
    876      * @throws Exception
     907     * @throws WP_HTML_Unsupported_Exception
    877908     *
    878909     * @see https://html.spec.whatwg.org/#generate-implied-end-tags
     
    890921            in_array( $this->state->stack_of_open_elements->current_node(), $elements_with_implied_end_tags, true )
    891922        ) {
     923            $this->state->stack_of_open_elements->pop();
     924        }
     925    }
     926
     927    /*
     928     * Closes elements that have implied end tags, thoroughly.
     929     *
     930     * See the HTML specification for an explanation why this is
     931     * different from {@see WP_HTML_Processor::generate_implied_end_tags}.
     932     *
     933     * @since 6.4.0
     934     *
     935     * @see https://html.spec.whatwg.org/#generate-implied-end-tags
     936     */
     937    private function generate_implied_end_tags_thoroughly() {
     938        $elements_with_implied_end_tags = array(
     939            'P',
     940        );
     941
     942        while ( in_array( $this->state->stack_of_open_elements->current_node(), $elements_with_implied_end_tags, true ) ) {
    892943            $this->state->stack_of_open_elements->pop();
    893944        }
  • trunk/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php

    r56299 r56331  
    5050            'P',
    5151            'SMALL',
     52            'SPAN',
    5253            'STRIKE',
    5354            'STRONG',
     
    192193            'SOURCE',
    193194            'SPACER', // Deprecated
    194             'SPAN',
    195195            'STYLE',
    196196            'SUB',
Note: See TracChangeset for help on using the changeset viewer.