Make WordPress Core

Changeset 58677

Timestamp:
07/05/2024 12:50:19 AM (4 weeks 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.

Location:
trunk
Files:
6 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 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
  • trunk/src/wp-includes/html-api/class-wp-html-processor.php

    r58676 r58677  
    102102 *  - Containers: ADDRESS, BLOCKQUOTE, DETAILS, DIALOG, DIV, FOOTER, HEADER, MAIN, MENU, SPAN, SUMMARY.
    103103 *  - Custom elements: All custom elements are supported. :)
    104  *  - Form elements: BUTTON, DATALIST, FIELDSET, INPUT, LABEL, LEGEND, METER, PROGRESS, SEARCH.
     104 *  - Form elements: BUTTON, DATALIST, FIELDSET, INPUT, LABEL, LEGEND, METER, .
    105105 *  - Formatting elements: B, BIG, CODE, EM, FONT, I, PRE, SMALL, STRIKE, STRONG, TT, U, WBR.
    106106 *  - Heading elements: H1, H2, H3, H4, H5, H6, HGROUP.
     
    757757                case WP_HTML_Processor_State::INSERTION_MODE_IN_BODY:
    758758                    return $this->step_in_body();
     759
     760
     761
     762
     763
     764
    759765
    760766                default:
     
    13351341            case '+SOURCE':
    13361342            case '+TRACK':
     1343
     1344
     1345
     1346
     1347
     1348
     1349
     1350
     1351
     1352
     1353
     1354
     1355
     1356
     1357
     1358
     1359
     1360
     1361
     1362
     1363
     1364
     1365
     1366
     1367
     1368
     1369
     1370
     1371
     1372
     1373
     1374
     1375
     1376
     1377
     1378
     1379
     1380
     1381
     1382
     1383
     1384
    13371385                $this->insert_html_element( $this->state->current_token );
    13381386                return true;
     
    13791427            case 'NOSCRIPT':
    13801428            case 'OBJECT':
    1381             case 'OPTGROUP':
    1382             case 'OPTION':
    13831429            case 'PLAINTEXT':
    13841430            case 'RB':
     
    13881434            case 'SARCASM':
    13891435            case 'SCRIPT':
    1390             case 'SELECT':
    13911436            case 'STYLE':
    13921437            case 'SVG':
     
    14471492            }
    14481493        }
     1494
     1495
     1496
     1497
     1498
     1499
     1500
     1501
     1502
     1503
     1504
     1505
     1506
     1507
     1508
     1509
     1510
     1511
     1512
     1513
     1514
     1515
     1516
     1517
     1518
     1519
     1520
     1521
     1522
     1523
     1524
     1525
     1526
     1527
     1528
     1529
     1530
     1531
     1532
     1533
     1534
     1535
     1536
     1537
     1538
     1539
     1540
     1541
     1542
     1543
     1544
     1545
     1546
     1547
     1548
     1549
     1550
     1551
     1552
     1553
     1554
     1555
     1556
     1557
     1558
     1559
     1560
     1561
     1562
     1563
     1564
     1565
     1566
     1567
     1568
     1569
     1570
     1571
     1572
     1573
     1574
     1575
     1576
     1577
     1578
     1579
     1580
     1581
     1582
     1583
     1584
     1585
     1586
     1587
     1588
     1589
     1590
     1591
     1592
     1593
     1594
     1595
     1596
     1597
     1598
     1599
     1600
     1601
     1602
     1603
     1604
     1605
     1606
     1607
     1608
     1609
     1610
     1611
     1612
     1613
     1614
     1615
     1616
     1617
     1618
     1619
     1620
     1621
     1622
     1623
     1624
     1625
     1626
     1627
     1628
     1629
     1630
     1631
     1632
     1633
     1634
     1635
     1636
     1637
     1638
     1639
     1640
     1641
     1642
     1643
     1644
     1645
     1646
     1647
     1648
     1649
     1650
     1651
     1652
     1653
     1654
     1655
     1656
     1657
     1658
     1659
     1660
     1661
     1662
     1663
     1664
     1665
     1666
     1667
     1668
     1669
     1670
     1671
     1672
     1673
     1674
     1675
     1676
     1677
     1678
     1679
     1680
     1681
     1682
     1683
     1684
     1685
     1686
     1687
     1688
     1689
     1690
     1691
     1692
     1693
     1694
    14491695    }
    14501696
     
    20372283     *
    20382284     * @since 6.4.0
     2285
    20392286     *
    20402287     * @see https://html.spec.whatwg.org/#generate-implied-end-tags
     
    20472294            'DT',
    20482295            'LI',
     2296
     2297
    20492298            'P',
     2299
     2300
     2301
     2302
    20502303        );
    20512304
    2052         $current_node = $this->state->stack_of_open_elements->current_node();
     2305        $no_exclusions = ! isset( $except_for_this_element );
     2306
    20532307        while (
    2054             $current_node && $current_node->node_name !== $except_for_this_element &&
     2308            &&
    20552309            in_array( $this->state->stack_of_open_elements->current_node(), $elements_with_implied_end_tags, true )
    20562310        ) {
     
    20662320     *
    20672321     * @since 6.4.0
     2322
    20682323     *
    20692324     * @see WP_HTML_Processor::generate_implied_end_tags
     
    20722327    private function generate_implied_end_tags_thoroughly() {
    20732328        $elements_with_implied_end_tags = array(
     2329
     2330
    20742331            'DD',
    20752332            'DT',
    20762333            'LI',
     2334
     2335
    20772336            'P',
     2337
     2338
     2339
     2340
     2341
     2342
     2343
     2344
     2345
     2346
    20782347        );
    20792348
  • trunk/tests/phpunit/tests/html-api/wpHtmlProcessor.php

    r58363 r58677  
    407407            'NOSCRIPT'  => array( 'NOSCRIPT' ),
    408408            'OBJECT'    => array( 'OBJECT' ),
    409             'OPTGROUP'  => array( 'OPTGROUP' ),
    410             'OPTION'    => array( 'OPTION' ),
    411409            'PLAINTEXT' => array( 'PLAINTEXT' ),
    412410            'RB'        => array( 'RB' ),
     
    416414            'SARCASM'   => array( 'SARCASM' ),
    417415            'SCRIPT'    => array( 'SCRIPT' ),
    418             'SELECT'    => array( 'SELECT' ),
    419416            'STYLE'     => array( 'STYLE' ),
    420417            'SVG'       => array( 'SVG' ),
  • trunk/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php

    r58592 r58677  
    190190            'NOSCRIPT',
    191191            'OBJECT',
    192             'OPTGROUP',
    193             'OPTION',
    194192            'PLAINTEXT', // Neutralized.
    195193            'RB', // Neutralized.
     
    198196            'RTC', // Neutralized.
    199197            'SCRIPT',
    200             'SELECT',
    201198            'STYLE',
    202199            'SVG',
  • trunk/tests/phpunit/tests/html-api/wpHtmlSupportRequiredHtmlProcessor.php

    r57508 r58677  
    5959     */
    6060    public function test_generate_implied_end_tags_needs_support() {
    61         $this->ensure_support_is_added_everywhere( 'OPTGROUP' );
    62         $this->ensure_support_is_added_everywhere( 'OPTION' );
    6361        $this->ensure_support_is_added_everywhere( 'RB' );
    6462        $this->ensure_support_is_added_everywhere( 'RP' );
     
    8078        $this->ensure_support_is_added_everywhere( 'CAPTION' );
    8179        $this->ensure_support_is_added_everywhere( 'COLGROUP' );
    82         $this->ensure_support_is_added_everywhere( 'OPTGROUP' );
    83         $this->ensure_support_is_added_everywhere( 'OPTION' );
    8480        $this->ensure_support_is_added_everywhere( 'RB' );
    8581        $this->ensure_support_is_added_everywhere( 'RP' );
  • trunk/tests/phpunit/tests/html-api/wpHtmlSupportRequiredOpenElements.php

    r57508 r58677  
    309309         */
    310310        $this->ensure_support_is_added_everywhere( 'SVG' );
    311 
    312         // These elements are specific to SELECT scope.
    313         $this->ensure_support_is_added_everywhere( 'OPTGROUP' );
    314         $this->ensure_support_is_added_everywhere( 'OPTION' );
    315311    }
    316312}
Note: See TracChangeset for help on using the changeset viewer.