Skip to content

fix: stop serializer inserting trailing-backslash hard breaks and stripping blank lines on save#806

Open
mvanhorn wants to merge 26 commits into
refactoringhq:mainfrom
mvanhorn:fix/798-serializer-hardbreaks
Open

fix: stop serializer inserting trailing-backslash hard breaks and stripping blank lines on save#806
mvanhorn wants to merge 26 commits into
refactoringhq:mainfrom
mvanhorn:fix/798-serializer-hardbreaks

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Stops the rich-editor markdown serializer from rewriting users' source on every autosave by stripping BlockNote's lone trailing-backslash soft-break artifact in compactMarkdown.

blocksToMarkdownLossy emits a CommonMark hard break (a single trailing \) for every paragraph-internal line break, even ordinary soft breaks the user typed. compactMarkdown is already the post-processor for BlockNote output, so the cleanup lives there: a lone trailing \ is removed (restoring a plain soft break) while an authored double-backslash \\ hard break is preserved untouched. Fenced code blocks (existing inCodeBlock guard) and indented code blocks (new guard) are left unchanged.

Why this matters

Issue #798: when a note is edited, the serializer inserts trailing \ hard breaks on single newlines inside a paragraph. For users who also edit notes outside Tolaria or paste prose from external sources, every autosave mutates the file on disk even when no semantic change was made, churning their source markdown.

Testing

  • pnpm exec vitest run src/utils/compact-markdown.test.ts — 35 passed (5 new: soft-break stripping, inline-closer soft breaks, authored double-backslash preservation, indented-code-block preservation, idempotency).
  • pnpm exec eslint src/utils/compact-markdown.ts src/utils/compact-markdown.test.ts — clean.
  • pnpm exec tsc --noEmit — clean.
  • Full src/utils/ suite green except one pre-existing, unrelated failure in releaseDownloadPage.test.ts (Windows authenticode workflow YAML), which also fails on the unmodified base.

New behavior covered:

  • Single newline inside a paragraph serializes without a trailing \.
  • Authored \\ hard break is preserved.
  • Indented and fenced code blocks are never mutated.
  • Idempotent: serializing already-serialized output is byte-identical (no churn on a no-op save).

Fixes #798

AI was used for assistance.

Strip BlockNote's lone trailing-backslash soft-break artifact in
compactMarkdown so ordinary paragraph-internal newlines stay soft
breaks, while preserving authored double-backslash hard breaks and
leaving fenced and indented code blocks untouched.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mvanhorn

mvanhorn commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

The Frontend Tests & Quality Checks failure reproduces on main's own CI (latest main run fails the same workflow), so it isn't introduced by this PR's serializer change.

github-actions Bot added 25 commits June 5, 2026 13:44
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.

Editor serializer inserts trailing backslash hard-breaks and strips blank lines on save

1 participant