Skip to content

fix: only escape markdown text where it would be read as syntax - #4038

Merged
JammingBen merged 1 commit into
mainfrom
fix/md-no-entity-escaping
Oct 29, 2026
Merged

JammingBen merged 1 commit into
mainfrom
fix/md-no-entity-escaping

Conversation

@JammingBen

Copy link
Copy Markdown
Member

Description

Saving a markdown file in the text editor rewrote plain text: tiptap escapes every special character, so Q&A became Q&amp;A, a < b became a &lt; b, snake_case became snake\_case, and so on. Each save changed the file, and full-text search no longer found terms containing &.

Text is now only escaped where markdown would actually read it as syntax:

  • & only when it starts an entity reference (&amp;, &#38;, &copy;)
  • < only when followed by a non-whitespace character (tags, comments, autolinks)
  • \ only before punctuation, a line break or at the end
  • _ not inside words
  • * and ~ not when surrounded by whitespace
  • `, [ and ] always
  • > never inline. The paragraph serializer escapes > and * at line starts, so they don't turn into blockquotes or list items

The serializer and the clipboard both use the same escaping. Text inside code is untouched.

This works around ueberdosis/tiptap#8471 by patching MarkdownManager.encodeTextForMarkdown and can be removed once tiptap only escapes where needed.

Related Issue

@JammingBen JammingBen self-assigned this Oct 27, 2026
@JammingBen
JammingBen marked this pull request as ready for review October 27, 2026 13:56
@JammingBen
JammingBen requested a review from kulmann October 27, 2026 13:56
@JammingBen
JammingBen force-pushed the fix/md-no-entity-escaping branch from 82b7ba7 to fc8ea91 Compare October 29, 2026 06:57

@kulmann kulmann left a comment

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.

My brain hurts now, but this is great 🥇

@JammingBen
JammingBen merged commit b19ccdb into main Oct 29, 2026
28 checks passed
@JammingBen
JammingBen deleted the fix/md-no-entity-escaping branch October 29, 2026 08:06
@openclouders openclouders mentioned this pull request Nov 2, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

text-editor saves & as &amp;, so full-text search no longer finds the note

2 participants