Skip to content

[Bug]: Rich markdown editor escapes brackets document-wide on any edit, corrupting GitHub alerts and callouts #22014

Closed

Description

@naanoo

Operating system

macOS

Orca version

1.4.206 (rule located in the shipped bundle, out/renderer/assets/rich-markdown-extensions-cEO8peYf.js)

Details

Editing a paragraph in the rich markdown editor backslash-escapes [, ], _, ~, ` and * across the whole document, including blocks that were never touched. Anything made of brackets is destroyed silently — GitHub alerts and callouts being the most visible casualty.

Here is a real reproduction. I opened one of our articles, typed a nonsense word into three body paragraphs, and saved. I did not touch a single callout. Diff of the saved file:

-Der Turing-Test ist ein Gedankenexperiment aus dem Jahr 1950 … wichtiger denn je.
+Der Turing-Test ist ein Gedankenexperiment aus dem Jahr 1950 … wichtiger denn je. rgffggf

-> [!wissenswert] Das Original war ein Ratespiel um Mann und Frau
+> \[!wissenswert\] Das Original war ein Ratespiel um Mann und Frau
 > In Turings Aufsatz heißt der Test "Imitation Game", und in der ersten Fassung …

-> [!zeitstrahl] 75 Jahre Imitation Game
+> \[!zeitstrahl\] 75 Jahre Imitation Game
+>
 > - 1950 · Alan Turing veröffentlicht "Computing Machinery and Intelligence" …

-> [!achtung] Heißt "bestanden", dass die Maschine denkt?
+> \[!achtung\] Heißt "bestanden", dass die Maschine denkt?
 > Nein, und das ist der Einwand, den John Searle 1980 mit dem Chinesischen Zimmer …

-> [!selbsttest]
+> \[!selbsttest\]
+>
 > - Was hat Turing mit dem Test erreichen wollen? · …

Note the [!achtung] block: its body is an unchanged context line, its header picked up backslashes. The cursor was never in that section.

Three properties worth knowing before you go looking:

  • Switching views is harmless. Open a file and toggle between the rich editor and the source editor as often as you like — nothing changes. It takes an actual edit to trigger it.
  • It shows up before the save. After editing in the rich editor, switching to the source view already displays the escaped form. The serialization, not the write, is where it happens. Saving then commits it to disk.
  • Small files did not trigger it for me. A short fixture with no front matter, edited once on its last line, came back byte-identical. The article that broke has YAML front matter, ~50 lines, and was edited in three separate paragraphs. That smells like the canonical-output fallback described in [Bug]: Rich markdown editor mangles dollar-heavy files on open and rewrites them on save #20425 rather than a per-node escape on the edited block alone.

The failure mode is quiet, which is what makes it expensive: the editor renders the escaped text as ordinary text, the file saves without complaint, and the damage only appears wherever the document is rendered next. Ours reached a published page as a plain blockquote with visible \[!wissenswert\] markup, and we fixed the symptom days before we found the cause.

Cause

The editor has no node type for alerts — callout, alert, admonition and [!NOTE] do not appear anywhere in that chunk. So > [!NOTE] parses as a plain blockquote, the marker survives as a text node, and on the way back out it meets this (deminified, names preserved):

encodeTextForMarkdown(text, node, parent) {
  return parent?.type != null && this.codeTypes.has(parent.type)
      || (node.marks || []).some(m => this.codeTypes.has(typeof m === 'string' ? m : m.type))
    ? text
    : this.escapeMarkdownSyntax(normalize(text));
}

escapeMarkdownSyntax(text) {
  return text.replace(/([\\`*_[\]~])/g, '\\$1');
}

The only exemption is code. There is no context check, so the escape also fires on characters CommonMark would never have read as syntax:

Input Written back as Correct?
> [!NOTE] > \[!NOTE\] no — [!NOTE] is not a link reference
[^1] (footnote ref) \[^1\] no
[[Some Page]] (wikilink) \[\[Some Page\]\] no
user_name_field user\_name\_field no — intra-word _ is not emphasis
feature~2 feature\~2 no — a single ~ is not strikethrough

This is the mirror image of #20425, which is about escapes being deleted on load. Same file, opposite direction. As far as I can tell #20406 does not touch escapeMarkdownSyntax, so merging it would not fix this.

How can we reproduce it?

  1. Take a markdown file shaped like a real article: YAML front matter, several body paragraphs, and blockquote callouts between them — > [!NOTE], > [!TIP] or any > [!word] header line followed by body lines.
  2. Open it in the rich markdown editor.
  3. Control step: toggle to the source editor and back a few times, save nothing. The file stays byte-identical.
  4. Now type a word into two or three body paragraphs — not into a callout — and save.
  5. Every [!word] header in the file has become \[!word\], including the ones in sections you never visited. Blank > lines also get inserted between a callout header and a following list.

Anything else that might help?

A suggested direction, in order of how much of the problem it solves:

  1. Escape only what would reparse differently. Serialize the text unescaped, reparse, and escape only where the result differs from the intended node. That is the only rule that stays correct as syntax support grows, and fix(editor): stop the rich markdown editor from mangling dollar-heavy files #20406 already introduces a serializer-fidelity module that looks like the natural home for it.
  2. Failing that, make the existing rule context-aware. [ only where a link, image or reference could actually start; _ only at word boundaries; ~ only when doubled.
  3. Independently: give alerts a node type. > [!NOTE] is rendered by GitHub itself, and Markdown preview doesn't render callouts / GitHub-style alerts (> [!note]) #8441 and [Feature]: Full GitHub Flavored Markdown (GFM) support in Markdown preview and editor #9858 already ask for it. A real node would make this class of corruption impossible for the most common case and fix the preview at the same time.
  4. Regardless of the fix: do not rewrite blocks the user did not edit. Even a perfect escape rule will keep producing surprise diffs as long as one keystroke can reformat a whole file.

Happy to test a build against the file that broke.

Activity

  1. added
    os:macos
    on Sep 21, 2026
  2. AmethystLiang commented on Sep 22, 2026

    @AmethystLiang
    Contributor

    thanks for reporting. looking into it

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    os:macos

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions