fix(markdown): collapse soft line breaks into spaces - #8139
Conversation
✅ Deploy Preview for tiptap-embed ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
🦋 Changeset detectedLatest commit: 0a88753 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 |
📝 WalkthroughSummary
WalkthroughMarkdown parsing now collapses CommonMark soft line breaks into spaces while preserving newlines in fenced code blocks. Tests cover plain paragraphs, links, inline marks, and conversion fixtures. ChangesSoft line break parsing
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested labels: Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant MarkdownInput
participant MarkdownManager
participant ProseMirrorDocument
MarkdownInput->>MarkdownManager: Parse markdown
MarkdownManager->>MarkdownManager: Collapse soft line breaks in text tokens
MarkdownManager->>ProseMirrorDocument: Build text nodes with spaces
🚥 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.
🧹 Nitpick comments (1)
packages/markdown/__tests__/soft-line-break.spec.ts (1)
1-15: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd regression tests for code spans and hard breaks.
The suite covers fenced code blocks, but not the other preservation guarantees in this PR. Register the relevant extensions in the test manager and add cases proving that code-span newlines remain unchanged and explicit hard breaks remain
hardBreaknodes.As per coding guidelines, deterministic user-visible behavior should have unit-test coverage, and the PR objective explicitly includes preserving code-span newlines and explicit hard breaks.
🤖 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__/soft-line-break.spec.ts` around lines 1 - 15, Extend the “Soft line breaks” tests around the MarkdownManager setup to register the relevant hard-break extension, then add regression cases for inline code spans and explicit hard breaks. Verify code-span newlines are preserved unchanged and hard-break syntax parses into hardBreak nodes, while keeping the existing fenced-code coverage intact.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.
Nitpick comments:
In `@packages/markdown/__tests__/soft-line-break.spec.ts`:
- Around line 1-15: Extend the “Soft line breaks” tests around the
MarkdownManager setup to register the relevant hard-break extension, then add
regression cases for inline code spans and explicit hard breaks. Verify
code-span newlines are preserved unchanged and hard-break syntax parses into
hardBreak nodes, while keeping the existing fenced-code coverage intact.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro Plus
Run ID: 088595a0-5c61-47c8-b14d-393c26a071e2
📒 Files selected for processing (5)
.changeset/2026-07-29-collapse-soft-line-breaks.mdpackages/markdown/__tests__/conversion-files/soft-break-marks.tspackages/markdown/__tests__/soft-line-break.spec.tspackages/markdown/src/MarkdownManager.tspackages/markdown/src/utils.ts
Fixes
Fixes #8136
Changes and Review
marked keeps a soft-wrapped paragraph's newlines inside its
texttokens, leaning on the CommonMark rule that a soft break may render as either a space or a line ending in HTML, where whitespace collapses.MarkdownManagerlowers that text straight into a ProseMirror node, which has no whitespace collapsing, so underwhite-space: break-spacesa wrapped paragraph renders across several lines instead of one. This collapses each soft break and its flanking spaces to a single space in the two branches that turn atexttoken into a text node; code blocks and code spans don't route through those branches so they keep their newlines, and explicit hard breaks stayhardBreak. One existing round-trip fixture is updated to the collapsed form, reflecting the trade-off that a markdown to doc to markdown round trip loses the author's original wrap columns.To verify, parse
foo\nbarand check it yields a single paragraphfoo bar, or runpnpm vitest run packages/markdown.Checklist
Responsibility