Changeset 58676
- Timestamp:
- 07/04/2024 11:14:44 PM (9 months ago)
- Location:
- trunk/src/wp-includes/html-api
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/html-api/class-wp-html-open-elements.php
r58588 r58676 146 146 147 147 /** 148 * Indicates if the current node is of a given type or name. 149 * 150 * It's possible to pass either a node type or a node name to this function. 151 * In the case there is no current element it will always return `false`. 152 * 153 * Example: 154 * 155 * // Is the current node a text node? 156 * $stack->current_node_is( '#text' ); 157 * 158 * // Is the current node a DIV element? 159 * $stack->current_node_is( 'DIV' ); 160 * 161 * // Is the current node any element/tag? 162 * $stack->current_node_is( '#tag' ); 163 * 164 * @see WP_HTML_Tag_Processor::get_token_type 165 * @see WP_HTML_Tag_Processor::get_token_name 166 * 167 * @since 6.7.0 168 * 169 * @access private 170 * 171 * @param string $identity Check if the current node has this name or type (depending on what is provided). 172 * @return bool Whether there is a current element that matches the given identity, whether a token name or type. 173 */ 174 public function current_node_is( string $identity ): bool { 175 $current_node = end( $this->stack ); 176 if ( false === $current_node ) { 177 return false; 178 } 179 180 $current_node_name = $current_node->node_name; 181 182 return ( 183 $current_node_name === $identity || 184 ( '#doctype' === $identity && 'html' === $current_node_name ) || 185 ( '#tag' === $identity && ctype_upper( $current_node_name ) ) 186 ); 187 } 188 189 /** 148 190 * Returns whether an element is in a specific scope. 149 191 * -
trunk/src/wp-includes/html-api/class-wp-html-processor.php
r58656 r58676 1030 1030 1031 1031 $this->generate_implied_end_tags(); 1032 if ( $this->state->stack_of_open_elements->current_node()->node_name !== $token_name) {1032 if ( ! $this->state->stack_of_open_elements->current_node_is( $token_name ) ) { 1033 1033 // @todo Record parse error: this error doesn't impact parsing. 1034 1034 } … … 1095 1095 $this->generate_implied_end_tags(); 1096 1096 1097 if ( $this->state->stack_of_open_elements->current_node()->node_name !== $token_name) {1097 if ( ! $this->state->stack_of_open_elements->current_node_is( $token_name ) ) { 1098 1098 // @todo Record parse error: this error doesn't impact parsing. 1099 1099 } … … 1121 1121 $node_name = $is_li ? 'LI' : $node->node_name; 1122 1122 $this->generate_implied_end_tags( $node_name ); 1123 if ( $node_name !== $this->state->stack_of_open_elements->current_node()->node_name) {1123 if ( ! $this->state->stack_of_open_elements->current_node_is( $node_name ) ) { 1124 1124 // @todo Indicate a parse error once it's possible. This error does not impact the logic here. 1125 1125 } … … 1198 1198 $this->generate_implied_end_tags( $token_name ); 1199 1199 1200 if ( $token_name !== $this->state->stack_of_open_elements->current_node()->node_name) {1200 if ( ! $this->state->stack_of_open_elements->current_node_is( $token_name ) ) { 1201 1201 // @todo Indicate a parse error once it's possible. This error does not impact the logic here. 1202 1202 }
Note: See TracChangeset
for help on using the changeset viewer.