Skip to content

fix: Parse new lines in text/plain as line breaks (BLO-1170)#2712

Open
matthewlipski wants to merge 4 commits intomainfrom
markdown-new-line-breaks
Open

fix: Parse new lines in text/plain as line breaks (BLO-1170)#2712
matthewlipski wants to merge 4 commits intomainfrom
markdown-new-line-breaks

Conversation

@matthewlipski
Copy link
Copy Markdown
Collaborator

@matthewlipski matthewlipski commented May 6, 2026

Summary

Due to text/plain content from the clipboard being interpreted as Markdown content, single line breaks are parsed as spaces, as Markdown typically uses a \ character or 2 line breaks to indicate the start of a new paragraph.

However, this is not 100% consistent across Markdown renderer implementations, and GitHub, for example, does render single new lines as actual line breaks.

Therefore, this PR adds the same behaviour, as it's currently confusing when plain text with line breaks gets pasted into editor as a single line.

Closes #2693

Rationale

#2693 proposes parsing new lines as separate paragraph blocks. In this PR, however, they get parsed as hardBreak inline nodes.

This is intentional, as imo this is a more intuitive mapping of Markdown to BlockNote content, where 1 new line -> new line in paragraph and 2 new lines -> new paragraph.

Changes

  • Added remarkBreaks plugin to Markdown parsing pipeline.

Impact

N/A

Testing

Added unit testm

Screenshots/Video

N/A

Checklist

  • Code follows the project's coding standards.
  • Unit tests covering the new feature have been added.
  • All existing tests pass.
  • The documentation has been updated to reflect the new feature

Additional Notes

N/A

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced soft break handling in Markdown to HTML conversion. Single newlines now properly render as HTML line breaks, improving formatting display consistency across viewers.
  • Tests

    • Updated test data entries to validate soft break rendering behavior in Markdown parsing.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
blocknote Ready Ready Preview May 6, 2026 8:56am
blocknote-website Ready Ready Preview May 6, 2026 8:56am

Request Review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 6, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2ca0a9ee-93a7-43a2-adb8-82c43db2d8d8

📥 Commits

Reviewing files that changed from the base of the PR and between 0e1dff2 and 8ffb451.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (1)
  • packages/core/src/api/parsers/markdown/markdownToHtml.ts

📝 Walkthrough

Walkthrough

The PR updates markdown-to-HTML conversion to emit <br> tags for soft line breaks instead of plain newlines, and updates corresponding test data to reflect the new rendering behavior.

Changes

Soft Break Rendering & Test Updates

Layer / File(s) Summary
Core Implementation
packages/core/src/api/parsers/markdown/markdownToHtml.ts
Soft break handling in trySoftBreak now emits <br>\n instead of \n for single newlines in markdown.
Test Data
tests/src/unit/core/formatConversion/parse/parseTestInstances.ts
Test fixtures updated: "basic" markdown test adds a new line after numbered list item; "singleNewLines" test simplifies by removing a previous hunk region.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • nperez0111
  • YousefED

Poem

🐰 A soft break once just whispered a newline so shy,
Now it speaks bold <br> tags that catch the eye!
No more flattened lines in a paste-and-collapse dance,
Each line gets its moment—a proper chance! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: parsing new lines in plain text as line breaks, with a specific issue reference (BLO-1170).
Description check ✅ Passed The description covers most required sections (Summary, Rationale, Changes, Impact, Testing, Checklist) but contains a typo ('testm' instead of 'test') and documentation updates are marked as incomplete.
Linked Issues check ✅ Passed The changes directly address #2693 by implementing the remarkBreaks plugin to preserve line breaks in pasted plain text, mapping single newlines to hardBreak nodes and double newlines to paragraphs.
Out of Scope Changes check ✅ Passed All changes (test data updates and markdown parser enhancement) are directly related to implementing the remarkBreaks plugin to fix plain text line break handling per #2693.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch markdown-new-line-breaks

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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tests/src/unit/core/formatConversion/parse/parseTestInstances.ts (1)

1129-1135: ⚡ Quick win

Add a focused doubleNewLines markdown fixture.

Given the requirement is “single newline = hard break, double newline = new paragraph,” it’d be good to add one minimal test case dedicated to two consecutive newlines so this behavior doesn’t regress implicitly behind broader fixtures.

Suggested fixture addition
   {
     testCase: {
       name: "singleNewLines",
       content: `Line 1
 Line 2
 Line 3
 Line 4
 `,
     },
     executeTest: testParseMarkdown,
   },
+  {
+    testCase: {
+      name: "doubleNewLines",
+      content: `Line 1
+
+Line 2
+`,
+    },
+    executeTest: testParseMarkdown,
+  },
🤖 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 `@tests/src/unit/core/formatConversion/parse/parseTestInstances.ts` around
lines 1129 - 1135, Add a focused fixture next to the existing singleNewLines
testCase: create a new testCase object named "doubleNewLines" (consistent with
the surrounding testCase entries) whose content is two paragraphs separated by
exactly two consecutive newlines, e.g. "Line 1\n\nLine 2\n" so the parser is
explicitly tested for double-newline → new paragraph behavior; place it near the
"singleNewLines" entry so it runs with the same suite.
🤖 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 `@tests/src/unit/core/formatConversion/parse/parseTestInstances.ts`:
- Around line 1129-1135: Add a focused fixture next to the existing
singleNewLines testCase: create a new testCase object named "doubleNewLines"
(consistent with the surrounding testCase entries) whose content is two
paragraphs separated by exactly two consecutive newlines, e.g. "Line 1\n\nLine
2\n" so the parser is explicitly tested for double-newline → new paragraph
behavior; place it near the "singleNewLines" entry so it runs with the same
suite.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5fbc8a81-4aba-4641-a6f3-58c9e1ea7c9c

📥 Commits

Reviewing files that changed from the base of the PR and between 50b1328 and 0e1dff2.

⛔ Files ignored due to path filters (2)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • tests/src/unit/core/formatConversion/parse/__snapshots__/markdown/singleNewLines.json is excluded by !**/__snapshots__/**
📒 Files selected for processing (3)
  • packages/core/package.json
  • packages/core/src/api/parsers/markdown/parseMarkdown.ts
  • tests/src/unit/core/formatConversion/parse/parseTestInstances.ts

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 6, 2026

Open in StackBlitz

@blocknote/ariakit

npm i https://pkg.pr.new/@blocknote/ariakit@2712

@blocknote/code-block

npm i https://pkg.pr.new/@blocknote/code-block@2712

@blocknote/core

npm i https://pkg.pr.new/@blocknote/core@2712

@blocknote/mantine

npm i https://pkg.pr.new/@blocknote/mantine@2712

@blocknote/react

npm i https://pkg.pr.new/@blocknote/react@2712

@blocknote/server-util

npm i https://pkg.pr.new/@blocknote/server-util@2712

@blocknote/shadcn

npm i https://pkg.pr.new/@blocknote/shadcn@2712

@blocknote/xl-ai

npm i https://pkg.pr.new/@blocknote/xl-ai@2712

@blocknote/xl-docx-exporter

npm i https://pkg.pr.new/@blocknote/xl-docx-exporter@2712

@blocknote/xl-email-exporter

npm i https://pkg.pr.new/@blocknote/xl-email-exporter@2712

@blocknote/xl-multi-column

npm i https://pkg.pr.new/@blocknote/xl-multi-column@2712

@blocknote/xl-odt-exporter

npm i https://pkg.pr.new/@blocknote/xl-odt-exporter@2712

@blocknote/xl-pdf-exporter

npm i https://pkg.pr.new/@blocknote/xl-pdf-exporter@2712

commit: 8ffb451

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.

Plain text paste does not preserve line breaks — multi-line text is flattened into a single paragraph

1 participant