Make WordPress Core


Ignore:
Timestamp:
01/10/2024 02:03:57 PM (8 months ago)
Author:
dmsnell
Message:

HTML API: Add support for list elements.

Adds support for the following HTML elements to the HTML Processor:

  • LI, OL, UL.
  • DD, DL, DT.

Previously, these elements were not supported and the HTML Processor would bail when encountering them.
With this patch it will proceed to parse an HTML document when encountering those tags as long as other normal conditions don't cause it to bail (such as complicated format reconstruction).

Props audrasjb, jonsurrell, bernhard-reiter.
Fixes #60215.

File:
1 edited

Legend:

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

    r57186 r57264  
    130130
    131131            if ( in_array( $node->node_name, $termination_list, true ) ) {
    132                 return true;
     132                return false;
    133133            }
    134134        }
     
    167167     *
    168168     * @since 6.4.0
     169     * @since 6.5.0 Implemented: no longer throws on every invocation.
    169170     *
    170171     * @see https://html.spec.whatwg.org/#has-an-element-in-list-item-scope
    171      *
    172      * @throws WP_HTML_Unsupported_Exception Always until this function is implemented.
    173172     *
    174173     * @param string $tag_name Name of tag to check.
     
    176175     */
    177176    public function has_element_in_list_item_scope( $tag_name ) {
    178         throw new WP_HTML_Unsupported_Exception( 'Cannot process elements depending on list item scope.' );
    179 
    180         return false; // The linter requires this unreachable code until the function is implemented and can return.
     177        return $this->has_element_in_specific_scope(
     178            $tag_name,
     179            array(
     180                // There are more elements that belong here which aren't currently supported.
     181                'OL',
     182                'UL',
     183            )
     184        );
    181185    }
    182186
     
    376380     *
    377381     * @since 6.4.0
    378      */
    379     public function walk_up() {
     382     * @since 6.5.0 Accepts $above_this_node to start traversal above a given node, if it exists.
     383     *
     384     * @param ?WP_HTML_Token $above_this_node Start traversing above this node, if provided and if the node exists.
     385     */
     386    public function walk_up( $above_this_node = null ) {
     387        $has_found_node = null === $above_this_node;
     388
    380389        for ( $i = count( $this->stack ) - 1; $i >= 0; $i-- ) {
    381             yield $this->stack[ $i ];
     390            $node = $this->stack[ $i ];
     391
     392            if ( ! $has_found_node ) {
     393                $has_found_node = $node === $above_this_node;
     394                continue;
     395            }
     396
     397            yield $node;
    382398        }
    383399    }
Note: See TracChangeset for help on using the changeset viewer.