fix(markdown): escape leading block syntax when serializing paragraphs - #8140
fix(markdown): escape leading block syntax when serializing paragraphs#8140lazerg wants to merge 2 commits into
Conversation
✅ Deploy Preview for tiptap-embed ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
🦋 Changeset detectedLatest commit: d39dd40 The changes in this PR will be included in the next version bump. This PR includes changesets to release 74 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository YAML (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughSummary
WalkthroughMarkdown serialization now preserves escaped block syntax at paragraph line starts, preventing headings and lists from being created during parse–serialize–parse round-trips. Tests cover heading, list, ordered-list, and thematic-break markers, with a patch changeset added. ChangesMarkdown escape round-trip
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Paragraph
participant MarkdownManager
participant MarkdownParser
Paragraph->>MarkdownManager: serialize leading block marker text
MarkdownManager->>MarkdownManager: escape marker with line-start context
MarkdownManager-->>MarkdownParser: emit escaped Markdown
MarkdownParser-->>Paragraph: parse text as paragraph
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/markdown/__tests__/conversion.spec.ts (1)
782-817: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winExpand the round-trip test matrix.
Please add cases for
Title\n\\---,Title\n\\===, escaped GFM table rows, indented markers such as\\# text, and a thematic-break round-trip. These are explicitly part of the PR objective and are not covered by the current tests.As per coding guidelines, deterministic user-visible behavior should be covered by unit tests.
Also applies to: 819-831
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/markdown/__tests__/conversion.spec.ts` around lines 782 - 817, Expand the serialization round-trip tests around the existing leading block syntax cases in the conversion test suite. Add deterministic cases covering “Title” followed by escaped thematic breaks using \--- and \===, escaped GFM table rows, indented escaped markers such as “ \# text”, and a thematic-break round-trip; assert each expected serialized result and preserve the existing paragraph helper and test style.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/markdown/src/MarkdownManager.ts`:
- Around line 1128-1143: Update escapeBlockSyntax() to process the beginning of
every line in text, not only the overall string start, while allowing up to
three leading spaces. Escape ATX headings, unordered and multi-digit
ordered-list markers, thematic breaks, Setext heading underlines, and table rows
so inputs such as Title followed by --- or lines beginning with | cannot become
block syntax when reparsed.
---
Nitpick comments:
In `@packages/markdown/__tests__/conversion.spec.ts`:
- Around line 782-817: Expand the serialization round-trip tests around the
existing leading block syntax cases in the conversion test suite. Add
deterministic cases covering “Title” followed by escaped thematic breaks using
\--- and \===, escaped GFM table rows, indented escaped markers such as “ \#
text”, and a thematic-break round-trip; assert each expected serialized result
and preserve the existing paragraph helper and test style.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro Plus
Run ID: 3fb60ee0-3a46-4001-95a7-0d6d21298a74
📒 Files selected for processing (3)
.changeset/markdown-escape-block-syntax.mdpackages/markdown/__tests__/conversion.spec.tspackages/markdown/src/MarkdownManager.ts
Fixes
Fixes #8134
Changes and Review
The serializer already escaped inline markdown, but not block markers at the start of a line. So a paragraph holding
# not a headingwas written back without its backslash and re-parsed as a real heading (same for-,+, ordered-list numbers and---). Serializing now escapes a leading block marker on the first line of a top-level paragraph, so escaped block syntax stays a paragraph across a parse → serialize → parse round-trip. To check, parse\# not a heading, extract the markdown, and parse it again, or run the new round-trip tests inconversion.spec.ts.Checklist
Responsibility