Replace the rich text content between a tag opener and matching closer.
Description
When stopped on a tag opener, replace the content enclosed by it and its matching closer with the provided rich text.
Parameters
$rich_textstringrequired- The rich text to replace the original content with.
Source
public function replace_rich_text( $rich_text ) {
if ( $this->is_tag_closer() || ! $this->expects_closer() ) {
return false;
}
$depth = $this->get_current_depth();
$tag_name = $this->get_tag();
$this->set_bookmark( '_wp_block_bindings' );
// The bookmark names are prefixed with `_` so the key below has an extra `_`.
$tag_opener = $this->bookmarks['__wp_block_bindings'];
$start = $tag_opener->start + $tag_opener->length;
// Find matching tag closer.
while ( $this->next_token() && $this->get_current_depth() >= $depth ) {
}
if ( ! $this->is_tag_closer() || $tag_name !== $this->get_tag() ) {
return false;
}
$this->set_bookmark( '_wp_block_bindings' );
$tag_closer = $this->bookmarks['__wp_block_bindings'];
$end = $tag_closer->start;
$this->lexical_updates[] = new WP_HTML_Text_Replacement(
$start,
$end - $start,
$rich_text
);
return true;
}
User Contributed Notes
You must log in before being able to contribute a note or feedback.