Skip to content

Commit

Permalink
try fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed Nov 5, 2024
1 parent 541b4f6 commit dc3f1e6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class WP_HTML_Active_Formatting_Elements {
*
* @var WP_HTML_Token[]
*/
private $stack = array();
public $stack = array();

/**
* Reports if a specific node is in the stack of active formatting elements.
Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/html-api/class-wp-html-open-elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class WP_HTML_Open_Elements {
*
* @var bool
*/
private $has_p_in_button_scope = false;
public $has_p_in_button_scope = false;

/**
* A function that will be called when an item is popped off the stack of open elements.
Expand Down
63 changes: 26 additions & 37 deletions src/wp-includes/html-api/class-wp-html-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5286,8 +5286,6 @@ public function seek( $bookmark_name ): bool {
// Flush any pending updates to the document before beginning.
$this->get_updated_html();

echo 'Seeking to ' . $bookmark_name . "\n";

$actual_bookmark_name = "_{$bookmark_name}";
$processor_started_at = $this->state->current_token
? $this->bookmarks[ $this->state->current_token->bookmark_name ]->start
Expand Down Expand Up @@ -5325,8 +5323,8 @@ public function seek( $bookmark_name ): bool {
* and computation time.
*/
if ( 'backward' === $direction ) {
echo 'back: ' . "\n";
// Reset necessary parser state
$this->change_parsing_namespace( 'html' );
$this->state->frameset_ok = true;
$this->state->stack_of_template_insertion_modes = array();
$this->state->head_element = null;
Expand All @@ -5335,64 +5333,55 @@ public function seek( $bookmark_name ): bool {
$this->element_queue = array();
$this->current_element = null;

if ( null === $this->context_node ) {
echo 'full parser' . "\n";
/*
* In the case of a full parser, the processor needs to be
* reset to a clean state and start over.
*/
$this->state->stack_of_open_elements = new WP_HTML_Open_Elements();
$this->state->active_formatting_elements = new WP_HTML_Active_Formatting_Elements();
$this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_INITIAL;
/*
* In case the parser is a fragment parser, instead of clearing the
* parser state and starting fresh, calling the stack methods
* maintains the proper flags in the parser.
*/
foreach ( $this->state->stack_of_open_elements->walk_up() as $item ) {
if ( 'context-node' === $item->bookmark_name ) {
break;
}

$this->breadcrumbs = array();
$this->bytes_already_parsed = 0;
$this->parser_state = self::STATE_READY;
} else {
/*
* In case the parser is a fragment parser, instead of clearing the
* parser state and starting fresh, calling the stack methods
* maintains the proper flags in the parser.
*/
foreach ( $this->state->stack_of_open_elements->walk_up() as $item ) {
if ( 'context-node' === $item->bookmark_name ) {
break;
}
$this->state->stack_of_open_elements->remove_node( $item );
}

$this->state->stack_of_open_elements->remove_node( $item );
foreach ( $this->state->active_formatting_elements->walk_up() as $item ) {
if ( 'context-node' === $item->bookmark_name ) {
break;
}

foreach ( $this->state->active_formatting_elements->walk_up() as $item ) {
if ( 'context-node' === $item->bookmark_name ) {
break;
}
$this->state->active_formatting_elements->remove_node( $item );
}

$this->state->active_formatting_elements->remove_node( $item );
}
if ( null === $this->context_node ) {
$this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_INITIAL;
$this->breadcrumbs = array();

$this->bytes_already_parsed = 0;
$this->parser_state = self::STATE_READY;
} else {
parent::seek( 'context-node' );
$this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_IN_BODY;
$this->breadcrumbs = array_slice( $this->breadcrumbs, 0, 2 );
}
}


// When moving forwards, reparse the document until reaching the same location as the original bookmark.
if ( null !== $this->state->current_token && $bookmark_starts_at === $this->bookmarks[ $this->state->current_token->bookmark_name ]->start ) {
return true;
}

while ( var_dump( $this->next_token() ) ) {
echo 'bm starts at ' . $bookmark_starts_at . ' and current token starts at ' . $this->bookmarks[ $this->state->current_token->bookmark_name ]->start . "\n";
if ( $bookmark_starts_at === $this->bookmarks[ $this->state->current_token->bookmark_name ]->start ) {
while ( $this->next_token() ) {
$bm = $this->bookmarks[ $this->current_element->token->bookmark_name ];
if ( $bookmark_starts_at === $bm->start ) {
while ( isset( $this->current_element ) && WP_HTML_Stack_Event::POP === $this->current_element->operation ) {
$this->current_element = array_shift( $this->element_queue );
}
return true;
}
}

echo 'false' . "\n";
return false;
}

Expand Down
2 changes: 0 additions & 2 deletions src/wp-includes/html-api/class-wp-html-tag-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,6 @@ private function base_class_next_token(): bool {
$was_at = $this->bytes_already_parsed;
$this->after_tag();

Check failure on line 948 in src/wp-includes/html-api/class-wp-html-tag-processor.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Functions must not contain multiple empty lines in a row; found 2 empty lines
var_dump( $was_at, $this->parser_state );

// Don't proceed if there's nothing more to scan.
if (
Expand Down Expand Up @@ -2544,7 +2543,6 @@ public function has_bookmark( $bookmark_name ): bool {
* @return bool Whether the internal cursor was successfully moved to the bookmark's location.
*/
public function seek( $bookmark_name ): bool {
var_dump( $bookmark_name, $this->bookmarks );
if ( ! array_key_exists( $bookmark_name, $this->bookmarks ) ) {
_doing_it_wrong(
__METHOD__,
Expand Down

0 comments on commit dc3f1e6

Please sign in to comment.