Repository navigation
fix: HTML export/parse round trip ignoring empty blocks (BLO-873) - #2931
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThe HTML serializer now preserves empty inline blocks with an object replacement character. The HTML parser and Markdown exporter remove this marker. Export coverage includes an empty paragraph between two populated paragraphs. ChangesEmpty inline HTML preservation
Estimated code review effort: 3 (Moderate) | ~15–30 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
|
|
We'll need to get this passing again before merging |
@blocknote/ariakit
@blocknote/code-block
@blocknote/core
@blocknote/mantine
@blocknote/react
@blocknote/server-util
@blocknote/shadcn
@blocknote/xl-ai
@blocknote/xl-docx-exporter
@blocknote/xl-email-exporter
@blocknote/xl-multi-column
@blocknote/xl-odt-exporter
@blocknote/xl-pdf-exporter
commit: |
|
This works, however I just struggled to find out where all these 0xFFFC chars were coming from in my HTML. For example Thunderbird renders these ugly [OBJ] boxes whenever the character is present. I can strip them out, but it is still kind of weird. Wouldn't adding & nbsp ; or something be a better solution to the problem? |
adding a space would show up as the user typing a space which is not accurate to the content that was in the editor. I'm unsure that there is a great solution here since there are different user groups: the output of blocksToHTMLLossy, and the input of tryParseHTML. If you can come up with another way of communicating an empty block, that is in-band to the lossy html then that would be great |
|
Got it. Yes, perhaps this is the only way, I don't know the rationale behind it. I can only think of 2 alternatives:
Maybe none of these are viable... |
|
I think that br would conflict with our existing hardbreak parsing and add a hardbreak. So I'm unsure on that. I wouldn't want to introduce an option just for this |
Summary
This PR fixes empty paragraphs getting dropped when running to round trip of
blocksToHTMLLossy->tryParseHTMLToBlocks. The fix is to add a Unicode object replacement 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 character don't affect rendering the lossy HTML. For good measure though, the character is also stripped when parsing HTML to ensure full round-trip consistency.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
Additional Notes
N/A
Summary by CodeRabbit
Bug Fixes
Tests