Skip to content

Commit

Permalink
Do not need to worry about those elements after all
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed Aug 7, 2024
1 parent 00f9b68 commit 58be2d8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 46 deletions.
44 changes: 0 additions & 44 deletions src/wp-includes/html-api/class-wp-html-open-elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,28 +173,6 @@ public function count(): int {
return count( $this->stack );
}

/**
* Returns how many nodes are currently in the stack of open elements.
*
* @since 6.7.0
*
* @todo I don't really like this, the proper solution is to not let non-element
* nodes onto the stack, but this is a way of checking if that approach fixes things.
*
* @return int How many node are in the stack of open elements.
*/
public function count_elements(): int {
$count = 0;
for ( $i = count( $this->stack ) - 1; $i >= 0; $i-- ) {
$node = $this->stack[ $i ];
if ( ctype_upper( $node->node_name[0] ) ) {
++$count;
}
}

return $count;
}

/**
* Returns the node at the end of the stack of open elements,
* if one exists. If the stack is empty, returns null.
Expand All @@ -209,28 +187,6 @@ public function current_node(): ?WP_HTML_Token {
return $current_node ? $current_node : null;
}

/**
* Returns the node at the end of the stack of open elements,
* if one exists. If the stack is empty, returns null.
*
* @since 6.7.0
*
* @todo I don't really like this, the proper solution is to not let non-element
* nodes onto the stack, but this is a way of checking if that approach fixes things.
*
* @return WP_HTML_Token|null Last node in the stack of open elements, if one exists, otherwise null.
*/
public function current_element_node(): ?WP_HTML_Token {
for ( $i = count( $this->stack ) - 1; $i >= 0; $i-- ) {
$node = $this->stack[ $i ];
if ( ctype_upper( $node->node_name[0] ) ) {
return $node;
}
}

return null;
}

/**
* Indicates if the current node is of a given type or name.
*
Expand Down
4 changes: 2 additions & 2 deletions src/wp-includes/html-api/class-wp-html-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5068,11 +5068,11 @@ private function generate_implied_end_tags_thoroughly(): void {
* @return WP_HTML_Token|null The adjusted current node.
*/
private function get_adjusted_current_node(): ?WP_HTML_Token {
if ( isset( $this->context_node ) && 1 === $this->state->stack_of_open_elements->count_elements() ) {
if ( isset( $this->context_node ) && 1 === $this->state->stack_of_open_elements->count() ) {
return $this->context_node;
}

return $this->state->stack_of_open_elements->current_element_node();
return $this->state->stack_of_open_elements->current_node();
}

/**
Expand Down

0 comments on commit 58be2d8

Please sign in to comment.