Repository navigation
fix(serializer): stop escaping Obsidian syntax and plain prose on save - #51
Merged
Merged
Conversation
remark-stringify escapes every `[`, `*`, `_` and `~` defensively. For an Obsidian vault that is destructive: saving an edited note rewrote `[[Note]]` as `\[\[Note]]`, `![[img.png]]` as `!\[\[img.png]]` and `> [!tip]` as `> \[!tip]`, which Obsidian renders as literal text. It also rewrote ordinary prose (`figure [1]`, `~3 cm`, `snake_case`). src/editor/escapes.ts removes each escape only when re-parsing proves the document unchanged: per-block bisection (memoized), then one whole-document parse as the proof, with a bounded whole-document fallback. It never re-implements CommonMark's escaping rules. Gates: tests/escapes.test.ts (search, fallback, parse budget, 200-case property over the real parser) and new obsidianPreserved / escapesKept classes plus a repair fixture in roundtrip.test.ts. Also adds Track H (hardening), Track M (medical & radiology students) and §9 (unplaced value areas) to ROADMAP.md, and fixes a stale README line. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cape fix Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
Author
Real-vault check (headless)I ran every note in a 179-note personal Obsidian vault through the same split → round-trip → rejoin that
Across the whole vault, the only differences between Pre-existing issues found by the same run are recorded in ROADMAP H0b and are not fixed here:
Interactive verification in the dev app is next. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Saving an edited note backslash-escaped Obsidian syntax. Obsidian renders the result as literal text, so every link, embedded image and callout in that note broke:
[[Pneumothorax]]\[\[Pneumothorax]]![[scan.png]]!\[\[scan.png]]> [!tip] Pearl> \[!tip] PearlThe same defensive escaping also rewrote ordinary prose:
figure [1],~3 cm,5 * 3,snake_case. Notes that were only opened were never affected. This is a §3.2 round-trip bug, the same class as the front-matter corruption fixed in v1.0.0.Fix
src/editor/escapes.ts, called only fromdocToMarkdowninserializer.ts, removes an escape only when re-parsing proves the document unchanged. It never re-implements CommonMark/GFM escaping rules, so it cannot get them wrong. It works in two passes:Escapes that are actually needed stay: task markers, heading/list/quote markers, raw HTML.
A note damaged by an earlier save is repaired by the next edit and save. This is pinned as a fixture, because the changelog tells users it works.
Gates
tests/escapes.test.ts:tests/roundtrip.test.ts:obsidianPreservedclass (22 constructs) andescapesKeptclass (6 constructs).preserved.normalizedentries updated:<autolink>→ bare URL, superfluous escapes dropped, table padding beside[[x\|y]], and the repair fixture.pnpm typecheckpasses andpnpm testpasses (632 tests). No Rust changes.Cost
About one extra full parse per serialization. In jsdom: ~12 ms at 800 words, ~47 ms at 3k, ~180 ms at 12k. It is paid on the debounced change listener. The worst case (one needed escape among many) went from ~2.2 s to ~0.2 s at 12k words once verification moved to per-block. A follow-up is noted in ROADMAP H0: take the whole-document proof off the dirty check if very long notes feel slow.
Found while gating, not fixed here
Both reproduce on
mainand are recorded in CLAUDE.md §0 and ROADMAP H0:\gains a backslash on every save.Also in this PR (docs)
Not yet verified
The fix has not been checked in the running app against a real vault. That is in progress.
🤖 Generated with Claude Code