WP_HTML_Processor::next_visitable_token
Ensures internal accounting is maintained for HTML semantic rules while the underlying Tag Processor class is seeking to a bookmark.
This doesn't currently have a way to represent non-tags and doesn't process semantic rules for text nodes. For access to the raw tokens consider using WP_HTML_Tag_Processor instead.
Note that this method may call itself recursively. This is why it is not implemented as WP_HTML_Processor::next_token(), which instead calls this method similarly to how WP_HTML_Tag_Processor::next_token() calls the WP_HTML_Tag_Processor::base_class_next_token() method.
Method of the class: WP_HTML_Processor{}
Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.
No Hooks.
Returns
true|false.
Usage
// private - for code of main (parent) class only $result = $this->next_visitable_token(): bool;
Changelog
| Since 6.7.2 | Introduced. |
| Since 6.7.2 | Added for internal support. |
WP_HTML_Processor::next_visitable_token() WP HTML Processor::next visitable token code WP 6.9.1
private function next_visitable_token(): bool {
$this->current_element = null;
if ( isset( $this->last_error ) ) {
return false;
}
/*
* Prime the events if there are none.
*
* @todo In some cases, probably related to the adoption agency
* algorithm, this call to step() doesn't create any new
* events. Calling it again creates them. Figure out why
* this is and if it's inherent or if it's a bug. Looping
* until there are events or until there are no more
* tokens works in the meantime and isn't obviously wrong.
*/
if ( empty( $this->element_queue ) && $this->step() ) {
return $this->next_visitable_token();
}
// Process the next event on the queue.
$this->current_element = array_shift( $this->element_queue );
if ( ! isset( $this->current_element ) ) {
// There are no tokens left, so close all remaining open elements.
while ( $this->state->stack_of_open_elements->pop() ) {
continue;
}
return empty( $this->element_queue ) ? false : $this->next_visitable_token();
}
$is_pop = WP_HTML_Stack_Event::POP === $this->current_element->operation;
/*
* The root node only exists in the fragment parser, and closing it
* indicates that the parse is complete. Stop before popping it from
* the breadcrumbs.
*/
if ( 'root-node' === $this->current_element->token->bookmark_name ) {
return $this->next_visitable_token();
}
// Adjust the breadcrumbs for this event.
if ( $is_pop ) {
array_pop( $this->breadcrumbs );
} else {
$this->breadcrumbs[] = $this->current_element->token->node_name;
}
// Avoid sending close events for elements which don't expect a closing.
if ( $is_pop && ! $this->expects_closer( $this->current_element->token ) ) {
return $this->next_visitable_token();
}
return true;
}