Make WordPress Core

Changeset 58679

Timestamp:
07/05/2024 04:37:41 PM (4 weeks ago)
Author:
dmsnell
Message:

HTML API: Stub out remaining insertion modes in the HTML Processor.

As part of work to add more spec support to the HTML API, this patch adds
stubs for all of the remaining parser insertion modes in the HTML Processor.
These modes are not all supported yet, but they will be necessary to continue
adding support for other tags and markup.

Developed in https://github.com/WordPress/wordpress-develop/pull/6973
Discussed in https://core.trac.wordpress.org/ticket/61576

Props dmsnell, jonsurrell.
See #61576.

Location:
trunk/src/wp-includes/html-api
Files:
2 edited

Legend:

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

    r58656 r58679  
    4949
    5050    /**
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
     100
     101
     102
     103
     104
     105
     106
     107
     108
     109
     110
    51111     * In body insertion mode for full HTML parser.
    52112     *
     
    61121
    62122    /**
     123
     124
     125
     126
     127
     128
     129
     130
     131
     132
     133
     134
     135
     136
     137
     138
     139
     140
     141
     142
     143
     144
     145
     146
     147
     148
     149
     150
     151
     152
     153
     154
     155
     156
     157
     158
     159
     160
     161
     162
     163
     164
     165
     166
     167
     168
     169
     170
     171
     172
     173
     174
     175
     176
     177
     178
     179
     180
     181
     182
     183
     184
     185
     186
     187
     188
     189
     190
     191
     192
     193
     194
     195
     196
     197
     198
     199
     200
     201
     202
     203
     204
     205
     206
    63207     * In select insertion mode for full HTML parser.
    64208     *
     
    85229
    86230    /**
    87      * In table insertion mode for full HTML parser.
    88      *
    89      * @since 6.7.0
    90      *
    91      * @see https://html.spec.whatwg.org/#parsing-main-intable
    92      * @see WP_HTML_Processor_State::$insertion_mode
    93      *
    94      * @var string
    95      */
    96     const INSERTION_MODE_IN_TABLE = 'insertion-mode-in-table';
    97 
    98     /**
    99      * In caption insertion mode for full HTML parser.
    100      *
    101      * @since 6.7.0
    102      *
    103      * @see https://html.spec.whatwg.org/#parsing-main-incaption
    104      * @see WP_HTML_Processor_State::$insertion_mode
    105      *
    106      * @var string
    107      */
    108     const INSERTION_MODE_IN_CAPTION = 'insertion-mode-in-caption';
    109 
    110     /**
    111      * In table body insertion mode for full HTML parser.
    112      *
    113      * @since 6.7.0
    114      *
    115      * @see https://html.spec.whatwg.org/#parsing-main-intablebody
    116      * @see WP_HTML_Processor_State::$insertion_mode
    117      *
    118      * @var string
    119      */
    120     const INSERTION_MODE_IN_TABLE_BODY = 'insertion-mode-in-table-body';
    121 
    122     /**
    123      * In row insertion mode for full HTML parser.
    124      *
    125      * @since 6.7.0
    126      *
    127      * @see https://html.spec.whatwg.org/#parsing-main-inrow
    128      * @see WP_HTML_Processor_State::$insertion_mode
    129      *
    130      * @var string
    131      */
    132     const INSERTION_MODE_IN_ROW = 'insertion-mode-in-row';
    133 
    134     /**
    135      * In cell insertion mode for full HTML parser.
    136      *
    137      * @since 6.7.0
    138      *
    139      * @see https://html.spec.whatwg.org/#parsing-main-incell
    140      * @see WP_HTML_Processor_State::$insertion_mode
    141      *
    142      * @var string
    143      */
    144     const INSERTION_MODE_IN_CELL = 'insertion-mode-in-cell';
    145 
    146     /**
    147      * In column group insertion mode for full HTML parser.
    148      *
    149      * @since 6.7.0
    150      *
    151      * @see https://html.spec.whatwg.org/#parsing-main-incolumngroup
    152      * @see WP_HTML_Processor_State::$insertion_mode
    153      *
    154      * @var string
    155      */
    156     const INSERTION_MODE_IN_COLUMN_GROUP = 'insertion-mode-in-column-group';
     231     * In template insertion mode for full HTML parser.
     232     *
     233     * @since 6.7.0
     234     *
     235     * @see https://html.spec.whatwg.org/#parsing-main-intemplate
     236     * @see WP_HTML_Processor_State::$insertion_mode
     237     *
     238     * @var string
     239     */
     240    const INSERTION_MODE_IN_TEMPLATE = 'insertion-mode-in-template';
     241
     242    /**
     243     * After body insertion mode for full HTML parser.
     244     *
     245     * @since 6.7.0
     246     *
     247     * @see https://html.spec.whatwg.org/#parsing-main-afterbody
     248     * @see WP_HTML_Processor_State::$insertion_mode
     249     *
     250     * @var string
     251     */
     252    const INSERTION_MODE_AFTER_BODY = 'insertion-mode-after-body';
    157253
    158254    /**
     
    169265
    170266    /**
    171      * In head insertion mode for full HTML parser.
    172      *
    173      * @since 6.7.0
    174      *
    175      * @see https://html.spec.whatwg.org/#parsing-main-inhead
    176      * @see WP_HTML_Processor_State::$insertion_mode
    177      *
    178      * @var string
    179      */
    180     const INSERTION_MODE_IN_HEAD = 'insertion-mode-in-head';
    181 
    182     /**
    183      * Before head insertion mode for full HTML parser.
    184      *
    185      * @since 6.7.0
    186      *
    187      * @see https://html.spec.whatwg.org/#parsing-main-beforehead
    188      * @see WP_HTML_Processor_State::$insertion_mode
    189      *
    190      * @var string
    191      */
    192     const INSERTION_MODE_BEFORE_HEAD = 'insertion-mode-before-head';
    193 
    194     /**
    195      * After head insertion mode for full HTML parser.
    196      *
    197      * @since 6.7.0
    198      *
    199      * @see https://html.spec.whatwg.org/#parsing-main-afterhead
    200      * @see WP_HTML_Processor_State::$insertion_mode
    201      *
    202      * @var string
    203      */
    204     const INSERTION_MODE_AFTER_HEAD = 'insertion-mode-after-head';
    205 
    206     /**
    207      * In template insertion mode for full HTML parser.
    208      *
    209      * @since 6.7.0
    210      *
    211      * @see https://html.spec.whatwg.org/#parsing-main-intemplate
    212      * @see WP_HTML_Processor_State::$insertion_mode
    213      *
    214      * @var string
    215      */
    216     const INSERTION_MODE_IN_TEMPLATE = 'insertion-mode-in-template';
     267     * insertion mode for full HTML parser.
     268     *
     269     * @since 6.7.0
     270     *
     271     * @see https://html.spec.whatwg.org/#parsing-main-
     272     * @see WP_HTML_Processor_State::$insertion_mode
     273     *
     274     * @var string
     275     */
     276    const INSERTION_MODE_';
     277
     278    /**
     279     * insertion mode for full HTML parser.
     280     *
     281     * @since 6.7.0
     282     *
     283     * @see https://html.spec.whatwg.org/#
     284     * @see WP_HTML_Processor_State::$insertion_mode
     285     *
     286     * @var string
     287     */
     288    const INSERTION_MODE_';
     289
     290    /**
     291     * After insertion mode for full HTML parser.
     292     *
     293     * @since 6.7.0
     294     *
     295     * @see https://html.spec.whatwg.org/#
     296     * @see WP_HTML_Processor_State::$insertion_mode
     297     *
     298     * @var string
     299     */
     300    const INSERTION_MODE_AFTER_';
     301
     302    /**
     303     * In insertion mode for full HTML parser.
     304     *
     305     * @since 6.7.0
     306     *
     307     * @see https://html.spec.whatwg.org/#parsing-main-in
     308     * @see WP_HTML_Processor_State::$insertion_mode
     309     *
     310     * @var string
     311     */
     312    const INSERTION_MODE_IN_';
    217313
    218314    /**
  • trunk/src/wp-includes/html-api/class-wp-html-processor.php

    r58677 r58679  
    755755        try {
    756756            switch ( $this->state->insertion_mode ) {
     757
     758
     759
     760
     761
     762
     763
     764
     765
     766
     767
     768
     769
     770
     771
     772
     773
     774
    757775                case WP_HTML_Processor_State::INSERTION_MODE_IN_BODY:
    758776                    return $this->step_in_body();
    759777
    760                 case WP_HTML_Processor_State::INSERTION_MODE_IN_HEAD:
    761                     return $this->step_in_head();
     778                case WP_HTML_Processor_State::INSERTION_MODE_IN_TABLE:
     779                    return $this->step_in_table();
     780
     781                case WP_HTML_Processor_State::INSERTION_MODE_IN_TABLE_TEXT:
     782                    return $this->step_in_table_text();
     783
     784                case WP_HTML_Processor_State::INSERTION_MODE_IN_CAPTION:
     785                    return $this->step_in_caption();
     786
     787                case WP_HTML_Processor_State::INSERTION_MODE_IN_COLUMN_GROUP:
     788                    return $this->step_in_column_group();
     789
     790                case WP_HTML_Processor_State::INSERTION_MODE_IN_TABLE_BODY:
     791                    return $this->step_in_table_body();
     792
     793                case WP_HTML_Processor_State::INSERTION_MODE_IN_ROW:
     794                    return $this->step_in_row();
     795
     796                case WP_HTML_Processor_State::INSERTION_MODE_IN_CELL:
     797                    return $this->step_in_cell();
    762798
    763799                case WP_HTML_Processor_State::INSERTION_MODE_IN_SELECT:
    764800                    return $this->step_in_select();
    765801
     802
     803
     804
     805
     806
     807
     808
     809
     810
     811
     812
     813
     814
     815
     816
     817
     818
     819
     820
     821
     822
     823
     824
     825
     826
    766827                default:
    767828                    $this->last_error = self::ERROR_UNSUPPORTED;
    768                     throw new WP_HTML_Unsupported_Exception( "No support for parsing in the '{$this->state->insertion_mode}' state." );
     829                    throw new WP_HTML_Unsupported_Exception( "." );
    769830            }
    770831        } catch ( WP_HTML_Unsupported_Exception $e ) {
     
    869930            ? count( $this->get_breadcrumbs() )
    870931            : $this->state->stack_of_open_elements->count();
     932
     933
     934
     935
     936
     937
     938
     939
     940
     941
     942
     943
     944
     945
     946
     947
     948
     949
     950
     951
     952
     953
     954
     955
     956
     957
     958
     959
     960
     961
     962
     963
     964
     965
     966
     967
     968
     969
     970
     971
     972
     973
     974
     975
     976
     977
     978
     979
     980
     981
     982
     983
     984
     985
     986
     987
     988
     989
     990
     991
     992
     993
     994
     995
     996
     997
     998
     999
     1000
     1001
     1002
     1003
     1004
     1005
     1006
     1007
     1008
     1009
     1010
     1011
     1012
     1013
     1014
     1015
     1016
     1017
     1018
     1019
     1020
     1021
     1022
     1023
     1024
     1025
     1026
     1027
     1028
     1029
     1030
     1031
     1032
     1033
     1034
     1035
     1036
     1037
     1038
     1039
     1040
     1041
     1042
     1043
     1044
     1045
     1046
     1047
     1048
     1049
     1050
     1051
    8711052    }
    8721053
     
    14951676
    14961677    /**
    1497      * Parses next element in the 'in head' insertion mode.
    1498      *
    1499      * This internal function performs the 'in head' insertion mode
     1678     * Parses next element in the 'in ' insertion mode.
     1679     *
     1680     * This internal function performs the 'in ' insertion mode
    15001681     * logic for the generalized WP_HTML_Processor::step() function.
    15011682     *
     
    15041685     * @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
    15051686     *
    1506      * @see https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inhead
     1687     * @see https://html.spec.whatwg.org/
    15071688     * @see WP_HTML_Processor::step
    15081689     *
    15091690     * @return bool Whether an element was found.
    15101691     */
    1511     private function step_in_head() {
     1692    private function step_in_table() {
     1693        $this->last_error = self::ERROR_UNSUPPORTED;
     1694        throw new WP_HTML_Unsupported_Exception( "No support for parsing in the '{$this->state->insertion_mode}' state." );
     1695    }
     1696
     1697    /**
     1698     * Parses next element in the 'in table text' insertion mode.
     1699     *
     1700     * This internal function performs the 'in table text' insertion mode
     1701     * logic for the generalized WP_HTML_Processor::step() function.
     1702     *
     1703     * @since 6.7.0 Stub implementation.
     1704     *
     1705     * @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
     1706     *
     1707     * @see https://html.spec.whatwg.org/#parsing-main-intabletext
     1708     * @see WP_HTML_Processor::step
     1709     *
     1710     * @return bool Whether an element was found.
     1711     */
     1712    private function step_in_table_text() {
     1713        $this->last_error = self::ERROR_UNSUPPORTED;
     1714        throw new WP_HTML_Unsupported_Exception( "No support for parsing in the '{$this->state->insertion_mode}' state." );
     1715    }
     1716
     1717    /**
     1718     * Parses next element in the 'in caption' insertion mode.
     1719     *
     1720     * This internal function performs the 'in caption' insertion mode
     1721     * logic for the generalized WP_HTML_Processor::step() function.
     1722     *
     1723     * @since 6.7.0 Stub implementation.
     1724     *
     1725     * @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
     1726     *
     1727     * @see https://html.spec.whatwg.org/#parsing-main-incaption
     1728     * @see WP_HTML_Processor::step
     1729     *
     1730     * @return bool Whether an element was found.
     1731     */
     1732    private function step_in_caption() {
     1733        $this->last_error = self::ERROR_UNSUPPORTED;
     1734        throw new WP_HTML_Unsupported_Exception( "No support for parsing in the '{$this->state->insertion_mode}' state." );
     1735    }
     1736
     1737    /**
     1738     * Parses next element in the 'in column group' insertion mode.
     1739     *
     1740     * This internal function performs the 'in column group' insertion mode
     1741     * logic for the generalized WP_HTML_Processor::step() function.
     1742     *
     1743     * @since 6.7.0 Stub implementation.
     1744     *
     1745     * @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
     1746     *
     1747     * @see https://html.spec.whatwg.org/#parsing-main-incolgroup
     1748     * @see WP_HTML_Processor::step
     1749     *
     1750     * @return bool Whether an element was found.
     1751     */
     1752    private function step_in_column_group() {
     1753        $this->last_error = self::ERROR_UNSUPPORTED;
     1754        throw new WP_HTML_Unsupported_Exception( "No support for parsing in the '{$this->state->insertion_mode}' state." );
     1755    }
     1756
     1757    /**
     1758     * Parses next element in the 'in table body' insertion mode.
     1759     *
     1760     * This internal function performs the 'in table body' insertion mode
     1761     * logic for the generalized WP_HTML_Processor::step() function.
     1762     *
     1763     * @since 6.7.0 Stub implementation.
     1764     *
     1765     * @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
     1766     *
     1767     * @see https://html.spec.whatwg.org/#parsing-main-intbody
     1768     * @see WP_HTML_Processor::step
     1769     *
     1770     * @return bool Whether an element was found.
     1771     */
     1772    private function step_in_table_body() {
     1773        $this->last_error = self::ERROR_UNSUPPORTED;
     1774        throw new WP_HTML_Unsupported_Exception( "No support for parsing in the '{$this->state->insertion_mode}' state." );
     1775    }
     1776
     1777    /**
     1778     * Parses next element in the 'in row' insertion mode.
     1779     *
     1780     * This internal function performs the 'in row' insertion mode
     1781     * logic for the generalized WP_HTML_Processor::step() function.
     1782     *
     1783     * @since 6.7.0 Stub implementation.
     1784     *
     1785     * @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
     1786     *
     1787     * @see https://html.spec.whatwg.org/#parsing-main-intr
     1788     * @see WP_HTML_Processor::step
     1789     *
     1790     * @return bool Whether an element was found.
     1791     */
     1792    private function step_in_row() {
     1793        $this->last_error = self::ERROR_UNSUPPORTED;
     1794        throw new WP_HTML_Unsupported_Exception( "No support for parsing in the '{$this->state->insertion_mode}' state." );
     1795    }
     1796
     1797    /**
     1798     * Parses next element in the 'in cell' insertion mode.
     1799     *
     1800     * This internal function performs the 'in cell' insertion mode
     1801     * logic for the generalized WP_HTML_Processor::step() function.
     1802     *
     1803     * @since 6.7.0 Stub implementation.
     1804     *
     1805     * @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
     1806     *
     1807     * @see https://html.spec.whatwg.org/#parsing-main-intd
     1808     * @see WP_HTML_Processor::step
     1809     *
     1810     * @return bool Whether an element was found.
     1811     */
     1812    private function step_in_cell() {
    15121813        $this->last_error = self::ERROR_UNSUPPORTED;
    15131814        throw new WP_HTML_Unsupported_Exception( "No support for parsing in the '{$this->state->insertion_mode}' state." );
     
    16931994         */
    16941995        return $this->step();
     1996
     1997
     1998
     1999
     2000
     2001
     2002
     2003
     2004
     2005
     2006
     2007
     2008
     2009
     2010
     2011
     2012
     2013
     2014
     2015
     2016
     2017
     2018
     2019
     2020
     2021
     2022
     2023
     2024
     2025
     2026
     2027
     2028
     2029
     2030
     2031
     2032
     2033
     2034
     2035
     2036
     2037
     2038
     2039
     2040
     2041
     2042
     2043
     2044
     2045
     2046
     2047
     2048
     2049
     2050
     2051
     2052
     2053
     2054
     2055
     2056
     2057
     2058
     2059
     2060
     2061
     2062
     2063
     2064
     2065
     2066
     2067
     2068
     2069
     2070
     2071
     2072
     2073
     2074
     2075
     2076
     2077
     2078
     2079
     2080
     2081
     2082
     2083
     2084
     2085
     2086
     2087
     2088
     2089
     2090
     2091
     2092
     2093
     2094
     2095
     2096
     2097
     2098
     2099
     2100
     2101
     2102
     2103
     2104
     2105
     2106
     2107
     2108
     2109
     2110
     2111
     2112
     2113
     2114
     2115
     2116
     2117
     2118
     2119
     2120
     2121
     2122
     2123
     2124
     2125
     2126
     2127
     2128
     2129
     2130
     2131
     2132
     2133
     2134
     2135
     2136
     2137
     2138
     2139
     2140
     2141
     2142
     2143
     2144
     2145
     2146
     2147
     2148
     2149
     2150
     2151
     2152
     2153
     2154
     2155
    16952156    }
    16962157
Note: See TracChangeset for help on using the changeset viewer.