Skip to content

Commit

Permalink
Use insert_marker over set_marker
Browse files Browse the repository at this point in the history
Use the method implemented in WordPress#6982
to avoid duplicating the same functionality.
  • Loading branch information
sirreal committed Jul 16, 2024
1 parent 2ded522 commit fce641d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@ public function current_node() {
return $current_node ? $current_node : null;
}

/**
* Inserts a "marker" at the end of the list of active formatting elements.
*
* > The markers are inserted when entering applet, object, marquee,
* > template, td, th, and caption elements, and are used to prevent
* > formatting from "leaking" into applet, object, marquee, template,
* > td, th, and caption elements.
*
* @see https://html.spec.whatwg.org/#concept-parser-marker
*
* @since 6.7.0
*/
public function insert_marker() {
$this->push( new WP_HTML_Token( null, 'marker', false ) );
}

/**
* Pushes a node onto the stack of active formatting elements.
*
Expand Down Expand Up @@ -185,10 +201,6 @@ public function walk_up() {
}
}

public function set_marker() {
$this->push( new WP_HTML_Token( null, 'marker', false ) );
}

/**
* Clears the list of active formatting elements up to the last marker.
*
Expand All @@ -208,9 +220,8 @@ public function set_marker() {
*/
public function clear_up_to_last_marker(): void {
foreach ( $this->walk_up() as $item ) {
$is_marker = 'marker' === $item->node_name;
array_pop( $this->stack );
if ( $is_marker ) {
if ( 'marker' === $item->node_name ) {
break;
}
}
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 @@ -1776,7 +1776,7 @@ private function step_in_table() {
*/
case '+CAPTION':
$this->clear_stack_to_table_context();
$this->state->active_formatting_elements->set_marker();
$this->state->active_formatting_elements->insert_marker();
$this->insert_html_element( $this->state->current_token );
$this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_IN_CAPTION;
return true;
Expand Down Expand Up @@ -2113,7 +2113,7 @@ private function step_in_row() {
case '+TD':
$this->clear_stack_to_table_row_context();
$this->insert_html_element( $this->state->current_token );
$this->state->active_formatting_elements->set_marker();
$this->state->active_formatting_elements->insert_marker();
return true;

/*
Expand Down

0 comments on commit fce641d

Please sign in to comment.