Hello marked world
'; + $stripped = wp_strip_inline_note_markers( $html ); + + $this->assertSame( 'Hello marked world
', $stripped ); + } + + public function test_strip_handles_multiple_markers_in_one_block() { + $html = 'a and b
'; + $stripped = wp_strip_inline_note_markers( $html ); + + $this->assertSame( 'a and b
', $stripped ); + } + + public function test_strip_passes_through_block_content_without_markers() { + $html = 'Plain text with no notes here.
'; + $stripped = wp_strip_inline_note_markers( $html ); + + $this->assertSame( $html, $stripped ); + } + + public function test_strip_keeps_other_classes_when_removing_wp_note() { + // The whole wrapper is removed, so any companion classes go with it. + $html = 'x
'; + $stripped = wp_strip_inline_note_markers( $html ); + + $this->assertSame( 'x
', $stripped ); + } + + public function test_strip_leaves_unrelated_marks_untouched() { + // A user highlight (`core/text-color`) serializes as a plain `` and + // must survive untouched. + $html = 'keep me
'; + $stripped = wp_strip_inline_note_markers( $html ); + + $this->assertSame( $html, $stripped ); + } + + public function test_strip_does_not_match_partial_class_names() { + // `wp-note-foo` is a different class and must not be treated as a marker; + // a regex word boundary would incorrectly match it. + $html = 'keep me
'; + $stripped = wp_strip_inline_note_markers( $html ); + + $this->assertSame( $html, $stripped ); + } + + public function test_strip_preserves_user_mark_attributes_next_to_note() { + // A user/plugin `` with several attributes sitting beside a note + // marker must be returned byte-for-byte; only the `wp-note` wrapper goes. + $html = 'user and noted
'; + $stripped = wp_strip_inline_note_markers( $html ); + + $this->assertSame( 'user and noted
', $stripped ); + } + + public function test_strip_preserves_nested_formatting() { + // A note wrapping already-formatted text (e.g. coloured text) serializes + // with nested inline elements. The wrapper is removed while the inner + // markup is preserved intact. + $html = 'a red b
'; + $stripped = wp_strip_inline_note_markers( $html ); + + $this->assertSame( 'a red b
', $stripped ); + } + + public function test_strip_unwraps_note_but_keeps_inner_highlight_mark() { + // A note wrapping a user highlight nests `` inside ``. Only the + // note wrapper is removed; the inner highlight `` is preserved, and + // the closer pairing must not unbalance. + $html = 'a hi b
'; + $stripped = wp_strip_inline_note_markers( $html ); + + $this->assertSame( 'a hi b
', $stripped ); + } + + public function test_strip_handles_overlapping_nested_note_markers() { + // Two notes anchored on overlapping text serialize as nested ``s. + // Both wrappers are removed and the text survives. + $html = 'abc
'; + $stripped = wp_strip_inline_note_markers( $html ); + + $this->assertSame( 'abc
', $stripped ); + } + + public function test_strip_ignores_mark_like_text_inside_a_comment() { + // A `` sequence inside an HTML comment is text, not a tag. Walking + // the parsed token stream ignores it; a raw regex over the string would + // mistake it for the note's closer, unbalance the pairing, and corrupt + // both the comment and the real wrapper. + $html = 'abtail
'; + $stripped = wp_strip_inline_note_markers( $html ); + + $this->assertSame( 'abtail
', $stripped ); + } + + public function test_strip_filter_is_registered_on_render_block() { + // Guards against future hook rewiring that would silently leave + // inline-note markers in rendered output. + $this->assertNotFalse( + has_filter( 'render_block', 'wp_strip_inline_note_markers' ) + ); + } +}