Skip to content

fix(core): keep an empty paragraph in the markdown round trip - #3450

Draft
YousefED wants to merge 2 commits into
mainfrom
fix/markdown-empty-paragraph
Draft

YousefED wants to merge 2 commits into
mainfrom
fix/markdown-empty-paragraph

Conversation

@YousefED

@YousefED YousefED commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

An empty paragraph now survives the markdown round trip in @blocknote/core. The export writes it as a <p></p> line, and the HTML parse reads a <p> without content as an empty paragraph.

Rationale

Markdown has no syntax for an empty paragraph. The export wrote a blank line, which the parse dropped (#1935). #2931 fixed this for HTML.

Changes

  • The markdown export writes an empty paragraph as <p></p>, also in a list item.
  • The paragraph parse rule accepts a <p> without child nodes. A <p> with only white space, a <br> or an image parses as before.
  • An empty <p> at the start of a list item stays the empty text of the item.
  • The markdown parser does not wrap a block-level HTML tag at the start of a list item in a <p>.

Impact

Pasted HTML with a fully empty <p></p> now gives an empty paragraph. Two parse snapshots of <details> in a list item lose an empty child paragraph.

Testing

New tests fail on main and pass. Browser tests pass in Chromium, Firefox and WebKit.

…m is raw HTML

The markdown parser wrapped the first line of each list item in a `<p>`,
also a line that starts a block of raw HTML (for example `1. <details>`).
A block element in a `<p>` is not valid HTML: the HTML parser closes the
`<p>` before the tag, and makes an empty `<p>` from the end tag `</p>`.
In `1. <details>`, that empty `<p>` went into the `<details>` element, and
the parse gave the list item a child paragraph that the text does not have.

Now such a line is a block of raw HTML, as at the top level, together with
the child lines that continue it. A blank line after it ends the block.

The parse snapshots of `- [ ] <details>` and `1. <details>` change: the
list item has no empty child paragraph. The result of
`1. <details>` with a summary and a body does not change.
Markdown has no syntax for an empty paragraph. The export wrote it as a
blank line, and the parse dropped it: the paragraphs "Before", empty,
"After" came back as two paragraphs.

Now the export writes an empty paragraph as the HTML tag `<p></p>` on
its own line, also for a child paragraph of a list item (with the indent
of the item). The markdown parser gives this line to the HTML parser as a
block of raw HTML.

The HTML parse of a paragraph rejected each `<p>` without text, so that
a `<p>` that only wraps an image is the image (#798). It now reads a `<p>`
without any child node as an empty paragraph. A `<p>` with only white
space, only a `<br>`, or only an image gives the same blocks as before.
Thus pasted HTML with `<p></p>` now gives an empty paragraph.

The list item parse leaves out such a `<p>` at the start of an `li`: it is
the empty text of the item, and the content after it stays the text of the
item, as before (`listItemEmptyParagraphBeforeContent`).

The markdown export snapshots of `paragraph/empty` and
`paragraph/emptyBetween` change to `<p></p>`.
@vercel

vercel Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
blocknote Ready Ready Preview Dec 1, 2026 11:28am UTC
blocknote-website Ready Ready Preview Dec 1, 2026 11:28am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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 on lines +1183 to +1188
const childContent = subLines
.join("\n")
.replace(
isHtmlBlockStart(firstLineContent) ? /\n+$/ : /^\n+|\n+$/g,
"",
);
@pkg-pr-new

pkg-pr-new Bot commented Dec 1, 2026

Copy link
Copy Markdown

Open in StackBlitz

@blocknote/ariakit

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

@blocknote/code-block

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

@blocknote/core

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

@blocknote/diagram-block

npm i https://pkg.pr.new/@blocknote/diagram-block@3450

@blocknote/mantine

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

@blocknote/math-block

npm i https://pkg.pr.new/@blocknote/math-block@3450

@blocknote/react

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

@blocknote/server-util

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

@blocknote/shadcn

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

@blocknote/xl-ai

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

@blocknote/xl-docx-exporter

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

@blocknote/xl-email-exporter

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

@blocknote/xl-multi-column

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

@blocknote/xl-odt-exporter

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

@blocknote/xl-pdf-exporter

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

@blocknote/xl-typst-exporter

npm i https://pkg.pr.new/@blocknote/xl-typst-exporter@3450

commit: bc96dc3

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.2

QR code for preview link

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

Built to branch gh-pages at 2026-12-01 11:36 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

YousefED added a commit that referenced this pull request Dec 3, 2026
33 lens tests fail since the merge of main. Each one is now a known failure (it.fails) with a comment that names its cause:

- 11 tests: the markdown of main loses an empty paragraph (pull request #3450 repairs it).
- 1 test: the markdown of main loses an empty list item.
- 1 test: the markdown export of main writes a URL in text without the escape, and the parse makes it a link.
- 20 tests (random seeds): an HTML text without blocks gives no block (#3400), and the editor keeps one empty paragraph.

The tests themselves do not change. The random tests now run the code of a seed in a function, so that the known seeds can run as known failures.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
YousefED added a commit that referenced this pull request Dec 3, 2026
…eries

The file tested the markdown fixes of this branch. Since the merge of main, the markdown code is the code of main, with its own tests and pull requests. 451 of the 594 cases of this file fail on that code. The behaviors that the lens needs and main does not have are recorded apart: an empty paragraph (pull request #3450), an empty list item, and a URL in text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch was successfully deployed

2 active deployments
Preview – blocknote-website — bc96dc3b Deployed Dec 1, 2026 by vercel[bot]
Preview – blocknote — bc96dc3b Deployed Dec 1, 2026 by vercel[bot]
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.

2 participants