Skip to content

Editor: Strip inline note markers from rendered block output#12215

Open
adamsilverstein wants to merge 2 commits into
WordPress:trunkfrom
adamsilverstein:backport/inline-note-markers-strip
Open

Editor: Strip inline note markers from rendered block output#12215
adamsilverstein wants to merge 2 commits into
WordPress:trunkfrom
adamsilverstein:backport/inline-note-markers-strip

Conversation

@adamsilverstein

@adamsilverstein adamsilverstein commented Jun 18, 2026

Copy link
Copy Markdown
Member

Summary

Backports the server-side piece of Gutenberg PR WordPress/gutenberg#78218, which adds inline (partial-text) Notes - notes anchored to a text selection within a block rather than to the whole block.

An inline note's anchor is an in-content <mark class="wp-note" data-id="N">…</mark> marker. The data-id identifies the note and the marker's position follows edits, so no separate selection metadata is stored. The marker stays in the raw post_content (and the REST raw view, revisions, and exports) so the editor can re-attach the note on reload, but the public front-end HTML should not expose note metadata.

This change strips that marker from rendered output only.

What changed

  • src/wp-includes/comment.php
    • wp_strip_inline_note_markers() — unwraps each note <mark> and its matching closer on render_block, keeping the marked text and any nested formatting.
  • src/wp-includes/default-filters.php
    • Registers the filter on render_block.
  • tests/phpunit/tests/comment/stripInlineNoteMarkers.php
    • Unit coverage for unwrapping, multi/overlapping/nested markers, pass-through, and the safety cases below.

Why the HTML API, not a regex

Matching goes through WP_HTML_Tag_Processor::has_class() so only the exact wp-note class token is targeted:

  • An unrelated user or plugin <mark> (a core/text-color highlight, or a wp-note-foo class) survives byte-for-byte with all attributes intact. A \bwp-note\b regex word boundary would wrongly match wp-note-foo.
  • A </mark>-looking sequence inside an HTML comment or attribute value is never mistaken for a real tag.
  • A nesting stack pairs each note opener with its own closer, so overlapping notes and nested highlight <mark>s resolve correctly.

The HTML API has no public token-removal method yet, so an anonymous WP_HTML_Tag_Processor subclass unwraps the marker directly on the parsed token stream.

Testing instructions

Run the new unit tests:

phpunit --filter Tests_Comment_StripInlineNoteMarkers

Or manually: add an inline note to a paragraph in the editor, view the post on the front end, and confirm the <mark class="wp-note"> wrapper is absent while the text remains, and that any non-note <mark> highlight is untouched.

Trac ticket: https://core.trac.wordpress.org/ticket/65482

Inline notes anchor to a text selection within a block using an in-content
`<mark class="wp-note" data-id="N">` marker so the anchor survives edits. The
marker is kept in raw `post_content` (and the REST `raw` view, revisions, and
exports) so the editor can re-attach on reload, but it must not reach public
HTML.

Add `wp_strip_inline_note_markers()`, hooked on `render_block`, which unwraps
each note `<mark>` and its matching closer while preserving the marked text and
any nested formatting. Matching goes through the HTML API rather than a regex so
only the exact `wp-note` class token is targeted: an unrelated user or plugin
`<mark>` (a `core/text-color` highlight, a `wp-note-foo` class) survives
byte-for-byte, and `</mark>`-looking text inside a comment or attribute value is
never mistaken for a real tag. A nesting stack pairs each note opener with its
own closer so overlapping notes and nested highlights resolve correctly.

Backports the server-side piece of Gutenberg PR 78218.
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props adamsilverstein.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

Copy link
Copy Markdown

Hi there! 👋

Thank you for your contribution to WordPress! 💖

It looks like this is your first pull request to wordpress-develop. Here are a few things to be aware of that may help you out!

No one monitors this repository for new pull requests. Pull requests must be attached to a Trac ticket to be considered for inclusion in WordPress Core. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description.

Pull requests are never merged on GitHub. The WordPress codebase continues to be managed through the SVN repository that this GitHub repository mirrors. Please feel free to open pull requests to work on any contribution you are making.

More information about how GitHub pull requests can be used to contribute to WordPress can be found in the Core Handbook.

Please include automated tests. Including tests in your pull request is one way to help your patch be considered faster. To learn about WordPress' test suites, visit the Automated Testing page in the handbook.

If you have not had a chance, please review the Contribute with Code page in the WordPress Core Handbook.

The Developer Hub also documents the various coding standards that are followed:

Thank you,
The WordPress Project

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

…7.1.0.

Inline notes are a 7.1 feature (trunk is 7.1-alpha and the Gutenberg
companion lives under lib/compat/wordpress-7.1/), and this function is
new, so the docblock should reference 7.1.0 rather than 6.9.0.
*/
class Tests_Comment_StripInlineNoteMarkers extends WP_UnitTestCase {

public function test_strip_unwraps_marker_from_mark() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add @ticket annotation for all new tests?

if ( true === $is_note ) {
$processor->remove_token();
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code assumes well-formed markup, which is fair for this task. the HTML Processor would guarantee that assumption, but would occasionally abort in certain cases of ill-formed markup.

everything else looks fine, though WPCS is going to complain about making multi-line comments without /* and */ — it prefers polluting diffs and making a big deal out of minor edits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants