Skip to content

fix(markdown): collapse soft line breaks into spaces - #8139

Open
lazerg wants to merge 1 commit into
ueberdosis:mainfrom
lazerg:fix/issue-8136-soft-break-collapse
Open

fix(markdown): collapse soft line breaks into spaces#8139
lazerg wants to merge 1 commit into
ueberdosis:mainfrom
lazerg:fix/issue-8136-soft-break-collapse

Conversation

@lazerg

@lazerg lazerg commented Jul 29, 2026

Copy link
Copy Markdown

Fixes

Fixes #8136

Changes and Review

marked keeps a soft-wrapped paragraph's newlines inside its text tokens, leaning on the CommonMark rule that a soft break may render as either a space or a line ending in HTML, where whitespace collapses. MarkdownManager lowers that text straight into a ProseMirror node, which has no whitespace collapsing, so under white-space: break-spaces a 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 a text token into a text node; code blocks and code spans don't route through those branches so they keep their newlines, and explicit hard breaks stay hardBreak. 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\nbar and check it yields a single paragraph foo bar, or run pnpm vitest run packages/markdown.

Checklist

  • I have added a changeset if necessary.
  • I have added tests if possible.
  • I have made sure to test my changes myself.

Responsibility

  • I have reviewed and understand these changes, and I take responsibility for this PR, even if an AI agent created it.

@lazerg
lazerg requested a review from a team as a code owner July 29, 2026 04:05
@netlify

netlify Bot commented Jul 29, 2026

Copy link
Copy Markdown

Deploy Preview for tiptap-embed ready!

Name Link
🔨 Latest commit 0a88753
🔍 Latest deploy log https://app.netlify.com/projects/tiptap-embed/deploys/6a697c1dbb30ec0008b2f991
😎 Deploy Preview https://deploy-preview-8139--tiptap-embed.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@changeset-bot

changeset-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0a88753

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 74 packages
Name Type
@tiptap/markdown Patch
@tiptap/core Patch
@tiptap/extension-audio Patch
@tiptap/extension-blockquote Patch
@tiptap/extension-bold Patch
@tiptap/extension-bubble-menu Patch
@tiptap/extension-bullet-list Patch
@tiptap/extension-code-block-lowlight Patch
@tiptap/extension-code-block Patch
@tiptap/extension-code Patch
@tiptap/extension-collaboration-caret Patch
@tiptap/extension-collaboration Patch
@tiptap/extension-color Patch
@tiptap/extension-details Patch
@tiptap/extension-document Patch
@tiptap/extension-drag-handle-react Patch
@tiptap/extension-drag-handle-vue-2 Patch
@tiptap/extension-drag-handle-vue-3 Patch
@tiptap/extension-drag-handle Patch
@tiptap/extension-emoji Patch
@tiptap/extension-file-handler Patch
@tiptap/extension-find-and-replace Patch
@tiptap/extension-floating-menu Patch
@tiptap/extension-font-family Patch
@tiptap/extension-hard-break Patch
@tiptap/extension-heading Patch
@tiptap/extension-highlight Patch
@tiptap/extension-horizontal-rule Patch
@tiptap/extension-image Patch
@tiptap/extension-invisible-characters Patch
@tiptap/extension-italic Patch
@tiptap/extension-link Patch
@tiptap/extension-list Patch
@tiptap/extension-mathematics Patch
@tiptap/extension-mention Patch
@tiptap/extension-node-range Patch
@tiptap/extension-ordered-list Patch
@tiptap/extension-paragraph Patch
@tiptap/extension-ruby-text Patch
@tiptap/extension-strike Patch
@tiptap/extension-subscript Patch
@tiptap/extension-superscript Patch
@tiptap/extension-table-of-contents Patch
@tiptap/extension-table Patch
@tiptap/extension-text-align Patch
@tiptap/extension-text-style Patch
@tiptap/extension-text Patch
@tiptap/extension-twitch Patch
@tiptap/extension-typography Patch
@tiptap/extension-underline Patch
@tiptap/extension-unique-id Patch
@tiptap/extension-youtube Patch
@tiptap/extensions Patch
@tiptap/html Patch
@tiptap/pm Patch
@tiptap/react Patch
@tiptap/starter-kit Patch
@tiptap/static-renderer Patch
@tiptap/suggestion Patch
@tiptap/vue-2 Patch
@tiptap/vue-3 Patch
@tiptap/extension-character-count Patch
@tiptap/extension-dropcursor Patch
@tiptap/extension-focus Patch
@tiptap/extension-gapcursor Patch
@tiptap/extension-history Patch
@tiptap/extension-list-item Patch
@tiptap/extension-list-keymap Patch
@tiptap/extension-placeholder Patch
@tiptap/extension-table-cell Patch
@tiptap/extension-table-header Patch
@tiptap/extension-table-row Patch
@tiptap/extension-task-item Patch
@tiptap/extension-task-list Patch

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

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Summary

  • Soft line breaks in Markdown paragraphs are now converted to spaces instead of literal newlines.
  • Newlines in code blocks and code spans are preserved, and explicit hard breaks are unchanged.
  • Added tests for plain text, links, and code blocks.
  • Updated the related round-trip fixture and added a patch changeset.

Walkthrough

Markdown 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.

Changes

Soft line break parsing

Layer / File(s) Summary
Soft break normalization and parser integration
packages/markdown/src/utils.ts, packages/markdown/src/MarkdownManager.ts
Adds collapseSoftBreaks and applies it to inline and fallback text tokens before HTML entity decoding.
Parsing coverage and release metadata
packages/markdown/__tests__/soft-line-break.spec.ts, packages/markdown/__tests__/conversion-files/soft-break-marks.ts, .changeset/2026-07-29-collapse-soft-line-breaks.md
Tests paragraph, link, inline-mark, and code-block behavior, updates conversion expectations, and declares a patch release.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested labels: area: markdown, complexity: medium, impact: medium

Suggested reviewers: bdbch

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
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is clear, concise, and matches the main change: collapsing soft line breaks into spaces in markdown parsing.
Description check ✅ Passed The description follows the template and includes the fix issue, change summary, verification steps, and checklist.
Linked Issues check ✅ Passed The changes satisfy #8136 by collapsing soft breaks in text parsing while keeping code blocks, code spans, and hard breaks intact.
Out of Scope Changes check ✅ Passed The changeset, parser update, and tests/fixture edits all support the stated soft line break fix and do not add unrelated scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot added area: markdown Markdown parsing and serialization complexity: medium Moderate change, possibly multiple files impact: medium Affects some users or workflows labels Jul 29, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/markdown/__tests__/soft-line-break.spec.ts (1)

1-15: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add 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 hardBreak nodes.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5158212 and 0a88753.

📒 Files selected for processing (5)
  • .changeset/2026-07-29-collapse-soft-line-breaks.md
  • packages/markdown/__tests__/conversion-files/soft-break-marks.ts
  • packages/markdown/__tests__/soft-line-break.spec.ts
  • packages/markdown/src/MarkdownManager.ts
  • packages/markdown/src/utils.ts

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

Labels

area: markdown Markdown parsing and serialization complexity: medium Moderate change, possibly multiple files impact: medium Affects some users or workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Markdown: CommonMark soft line breaks become literal \n in text nodes and render as visible line breaks

1 participant