Make WordPress Core


Ignore:
Timestamp:
07/05/2024 12:50:19 AM (2 years ago)
Author:
dmsnell
Message:

HTML API: Support SELECT insertion mode.

As part of work to add more spec support to the HTML API, this patch adds
support for the SELECT, OPTION, and OPTGROUP elements, including the
requisite support for the IN SELECT insertion mode.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/5908
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-open-elements.php

    r58676 r58677  
    190190         * Returns whether an element is in a specific scope.
    191191         *
    192          * ## HTML Support
    193          *
    194          * This function skips checking for the termination list because there
    195          * are no supported elements which appear in the termination list.
    196          *
    197192         * @since 6.4.0
    198193         *
    … …  
    312307         * Returns whether a particular element is in select scope.
    313308         *
    314          * @since 6.4.0
     309         * This test differs from the others like it, in that its rules are inverted.
     310         * Instead of arriving at a match when one of any tag in a termination group
     311         * is reached, this one terminates if any other tag is reached.
     312         *
     313         * > The stack of open elements is said to have a particular element in select scope when it has
     314         * > that element in the specific scope consisting of all element types except the following:
     315         * >   - optgroup in the HTML namespace
     316         * >   - option in the HTML namespace
     317         *
     318         * @since 6.4.0 Stub implementation (throws).
     319         * @since 6.7.0 Full implementation.
    315320         *
    316321         * @see https://html.spec.whatwg.org/#has-an-element-in-select-scope
    317322         *
    318          * @throws WP_HTML_Unsupported_Exception Always until this function is implemented.
    319          *
    320323         * @param string $tag_name Name of tag to check.
    321          * @return bool Whether given element is in scope.
     324         * @return bool Whether the given element is in SELECT scope.
    322325         */
    323326        public function has_element_in_select_scope( $tag_name ) {
    324                 throw new WP_HTML_Unsupported_Exception( 'Cannot process elements depending on select scope.' );
    325 
    326                 return false; // The linter requires this unreachable code until the function is implemented and can return.
     327                foreach ( $this->walk_up() as $node ) {
     328                        if ( $node->node_name === $tag_name ) {
     329                                return true;
     330                        }
     331
     332                        if (
     333                                'OPTION' !== $node->node_name &&
     334                                'OPTGROUP' !== $node->node_name
     335                        ) {
     336                                return false;
     337                        }
     338                }
     339
     340                return false;
    327341        }
    328342
Note: See TracChangeset for help on using the changeset viewer.