Skip to content

fix: HTML export/parse round trip ignoring empty blocks (BLO-873) - #2931

Open
matthewlipski wants to merge 1 commit into
mainfrom
parse-preserve-white-space
Open

fix: HTML export/parse round trip ignoring empty blocks (BLO-873)#2931
matthewlipski wants to merge 1 commit into
mainfrom
parse-preserve-white-space

Conversation

@matthewlipski

@matthewlipski matthewlipski commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR fixes empty paragraphs getting dropped when running to round trip of blocksToHTMLLossy -> tryParseHTMLToBlocks. The fix is to add an &nbsp character to empty blocks' inline content elements when exporting to lossy HTML. This causes the blocks to be parsed instead of ignored without introducing any other changes in behaviour. Markdown export/parse works the same, and the &nbsp character don't affect rendering the lossy HTML.

Closes #986

Rationale

Dropping empty blocks is a loss of information from the original document that I believe is never desirable for consumers. For this reason, Ive also opted to not make this behaviour configurable.

Changes

See above.

Impact

N/A

Testing

Added unit test case and updated existing HTML export snapshots.

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

    • Preserved empty paragraphs and other empty inline-content blocks during HTML export and re-import.
    • Prevented blank blocks between content from being dropped in round trips.
  • Tests

    • Added coverage for HTML containing an empty paragraph between two populated paragraphs.

@matthewlipski
matthewlipski requested a review from nperez0111 July 29, 2026 15:45
@vercel

vercel Bot commented Jul 29, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
blocknote Ready Ready Preview Jul 29, 2026 3:45pm
blocknote-website Ready Ready Preview Jul 29, 2026 3:45pm

Request Review

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a83b95ca-3ff0-4704-8490-0b33b7a5aa78

📥 Commits

Reviewing files that changed from the base of the PR and between dee7880 and 9011269.

⛔ Files ignored due to path filters (6)
  • tests/src/unit/core/formatConversion/export/__snapshots__/blocknoteHTML/paragraph/emptyBetween.html is excluded by !**/__snapshots__/**
  • tests/src/unit/core/formatConversion/export/__snapshots__/html/complex/misc.html is excluded by !**/__snapshots__/**
  • tests/src/unit/core/formatConversion/export/__snapshots__/html/paragraph/empty.html is excluded by !**/__snapshots__/**
  • tests/src/unit/core/formatConversion/export/__snapshots__/html/paragraph/emptyBetween.html is excluded by !**/__snapshots__/**
  • tests/src/unit/core/formatConversion/export/__snapshots__/markdown/paragraph/emptyBetween.md is excluded by !**/__snapshots__/**
  • tests/src/unit/core/formatConversion/export/__snapshots__/nodes/paragraph/emptyBetween.json is excluded by !**/__snapshots__/**
📒 Files selected for processing (2)
  • packages/core/src/api/exporters/html/util/serializeBlocksExternalHTML.ts
  • tests/src/unit/core/formatConversion/export/exportTestInstances.ts

📝 Walkthrough

Walkthrough

The HTML block serializer now preserves empty inline blocks by inserting a non-breaking space when their content DOM is empty. Export coverage adds a case for an empty paragraph between two populated paragraphs.

Changes

Empty inline HTML preservation

Layer / File(s) Summary
Serializer fallback and export coverage
packages/core/src/api/exporters/html/util/serializeBlocksExternalHTML.ts, tests/src/unit/core/formatConversion/export/exportTestInstances.ts
The serializer preserves empty non-code inline blocks with a non-breaking space, and tests an empty paragraph between “Before” and “After”.

Estimated code review effort: 3 (Moderate) | ~15–30 minutes

Suggested reviewers: nperez0111

Poem

I’m a bunny hopping through HTML bright,
Saving empty paragraphs from vanishing night.
A tiny space keeps each block in line,
Between “Before” and “After,” all things align.
Round trips now leave the meadow fine!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main fix: preserving empty blocks during HTML export/parse round trips.
Description check ✅ Passed The description follows the template with all required sections filled and includes summary, rationale, changes, impact, testing, and checklist.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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 parse-preserve-white-space

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.

@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://TypeCellOS.github.io/BlockNote/pr-preview/pr-2931/

Built to branch gh-pages at 2026-07-29 16:11 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

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.

Empty paragraphs are being removed

1 participant