Strips inline note markers from rendered block output.
Description
Inline notes - notes anchored to a text selection within a block rather than the whole block - are anchored in raw block content with <mark class="wp-note" data-id="N">...</mark> so the marker survives edits, but the public HTML should not expose note metadata. This filter unwraps the marker entirely - dropping the <mark> open tag and its matching closer while keeping the marked text - so nothing leaks to the front end. The raw post_content (and the REST raw view, revisions, exports) keeps the marker so the editor can re-attach it on reload. Only note markers are unwrapped: WP_HTML_Tag_Processor::has_class() matches the wp-note class by exact token, so a <mark> a user or plugin added (e.g. a core/text-color highlight, or an unrelated wp-note-foo class) is never flagged and survives byte-for-byte with all of its attributes intact. A naive regex would be wrong here: a \bwp-note\b word boundary also matches wp-note-foo, which is why the class check goes through the HTML API instead. The HTML API has no public token-removal method yet, so an anonymous WP_HTML_Tag_Processor subclass unwraps each note <mark> and its matching closer directly on the parsed token stream. Walking tokens - rather than matching <mark> with a regex - means a </mark>-looking sequence inside a comment or attribute value can never be mistaken for a real tag, and a nesting stack keeps each note opener paired with its own closer so overlapping notes and any user highlight <mark> left intact still resolve correctly. The low-level WP_HTML_Tag_Processor is used deliberately, rather than the tree-building WP_HTML_Processor. Note markers live in user-editable content, so the markup is not guaranteed to be well formed. On certain ill-formed nesting the tree builder aborts, which would leave note markers - and their metadata - in the rendered output. Scanning tokens instead removes every wp-note marker it encounters and degrades gracefully: an unbalanced or stray tag is left exactly as it was rather than corrupting surrounding markup.
Parameters
$block_contentstring
Rendered block HTML.
Return
string
Block HTML with wp-note markers unwrapped.
Uses · 2
str_contains()Polyfill for `str_contains()` function added in PHP 8.0.
4575functionwp_strip_inline_note_markers($block_content){4576if(!str_contains($block_content,'wp-note')){4577return$block_content;4578}45794580/*4581 * Anonymous subclass exposing token removal, which WP_HTML_Tag_Processor4582 * does not provide publicly yet. Removing the current token via its bookmark4583 * span unwraps the `<mark>` (opener or closer) while keeping the text it4584 * wraps.4585 */4586$processor=newclass($block_content)extendsWP_HTML_Tag_Processor{4587/**4588 * Removes the current token, keeping any text it wraps.4589 */4590publicfunctionremove_token():void{4591// Always called after next_tag() returned true, so the bookmark is set.4592$this->set_bookmark('here');4593$span=$this->bookmarks['here'];45944595$this->lexical_updates[]=newWP_HTML_Text_Replacement($span->start,$span->length,'');4596}4597};45984599/*4600 * Walk every `<mark>`, tracking note nesting on a stack so each note opener4601 * pairs with its own closer, and unwrap only the note markers.4602 */4603$mark_stack=array();4604$query=array(4605'tag_name'=>'MARK',4606'tag_closers'=>'visit',4607);4608while($processor->next_tag($query)){4609if($processor->is_tag_closer()){4610$is_note=array_pop($mark_stack);4611}else{4612$is_note=$processor->has_class('wp-note');4613$mark_stack[]=$is_note;4614}46154616if(true===$is_note){4617$processor->remove_token();4618}4619}46204621return$processor->get_updated_html();4622}
History
Introduced in 7.1.0.
Signature, return type and hooks compared across 1 parsed release.
About this page
Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/comment.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.