Skip to content

fix(core): keep the list start and the children of a list item in the HTML parse - #3403

Draft
YousefED wants to merge 3 commits into
fix/html-parse-detached-documentfrom
fix/html-list-item-children
Draft

YousefED wants to merge 3 commits into
fix/html-parse-detached-documentfrom
fix/html-list-item-children

Conversation

@YousefED

@YousefED YousefED commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Stack on #3393.

Two fixes for the HTML parse of lists, one commit for each. The markdown parse uses the HTML parse.

1. The start of a numbered list. Input: <ol start="2"><li>A<ul><li>B</li></ul></li><li>C</li></ol>

  • main: A has no start. The list starts at 1.
  • With the fix: A has start: 2.

Cause: the parser puts an item that has a nested list into a div. The parse rule read start from that div, not from the list.

2. The children of a list item. Input: <ul><li><p>A</p><ul><li><p>B</p></li></ul><p>C</p></li></ul>

  • main: bullet A with the child B, then a new bullet C.
  • With the fix: bullet A with the children B and paragraph C.

A nested list after a second block (<p>A</p><pre>…</pre><ul>…) also went out of its item. Cause: the parser moved only the nested list out of the <li>. Now all the nodes after the own content of the item move with it.

Testing

Notes

  • Text directly after a nested list keeps one space at its start if the HTML has white space there, as text after each other block does on main.
  • An item that starts with a nested list and has text after it (<li><ol>…</ol>tail</li>): the list goes to the item before it, as on main, and tail is now a paragraph (main: a list item). In a numbered list, the numbers after that paragraph start again. No known tool writes this form.
  • <ol start="6"><div><li>: the items in the first div get the start (main: no start). No known source writes this HTML.
  • An element whose text the parser ignores (<style>, <script>, <title>) before the paragraph of an item with a nested list gives an empty item with the paragraph as its child.

@vercel

vercel Bot commented Nov 22, 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 Nov 22, 2026 6:45pm UTC
blocknote-website Ready Ready Preview Nov 22, 2026 6:45pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 22, 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

@pkg-pr-new

pkg-pr-new Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@blocknote/ariakit

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

@blocknote/code-block

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

@blocknote/core

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

@blocknote/diagram-block

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

@blocknote/mantine

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

@blocknote/math-block

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

@blocknote/react

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

@blocknote/server-util

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

@blocknote/shadcn

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

@blocknote/xl-ai

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

@blocknote/xl-docx-exporter

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

@blocknote/xl-email-exporter

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

@blocknote/xl-multi-column

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

@blocknote/xl-odt-exporter

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

@blocknote/xl-pdf-exporter

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

@blocknote/xl-typst-exporter

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

commit: 1966327

@github-actions

github-actions Bot commented Nov 22, 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-3403/

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

The fault: the HTML parse lost the `start` of a numbered list (for
example `<ol start="2">`) if the first item of the list had a nested
list. The markdown parse uses the HTML parse, so `3. a` with a nested
list also became a list that starts at 1.

The cause: before the parse rules run, the parser puts a list item with
a nested list into a `div` element, together with the block group of
the nested list (`createGroups` in `nestedLists.ts`). The parse rule of
the numbered list item read the `start` attribute from the parent of
the `<li>`. For such an item, the parent is that `div`, and not the
list.

The fix: for an item in a `div`, the rule reads `start` from the parent
of the `div` (the list). It also uses the `div` to find out if the item
is the first item of the list, so that a later item with a nested list
does not get the start.

The rule does not tell a `div` of the HTML source from the `div` of the
parser. No known source writes `<ol><div><li>`.
The HTML parse moves a nested list out of its <li>, to make it a child
block of the list item. It did not keep the other nodes of the <li>
with the nested list:

- Each node after the nested list went into a new item of the outer
  list. A paragraph became a new bullet. An image became an empty bullet
  with the image as its child.
- When a block came between the content of the list item and the nested
  list (for example a code block), the nested list became a list after
  the list item, not a child of it.

The markdown parse uses the HTML parse, thus it had the same fault.

Now all the nodes after the own content of a list item move out of the
<li> together, in order, into the block group of the list item. The
parser makes the blocks from them. The own content is the text and the
inline elements up to the first block, or else that first block if it
is a paragraph, a heading, a code block or a quote with text. A comment,
white space and an element without text are not content. If the first
block is a different element (for example an image), the nodes before
the nested list stay in the <li>, as before.

Text directly after a nested list becomes a paragraph. It keeps one
space at its start if the HTML has white space there, as each text
after a block does in the parse (for example `<li><p>a</p> b</li>`).

A <li> that starts with a nested list has no content of its own. As
before, the nested list goes to the list item before it.

Test changes:
- nestedLists.test.ts.snap: in "content after nested list" and "content
  in between", the text is in the block group of the list item, not in a
  new <li>. The other 4 changed snapshots change only by white space:
  the white space after a nested list moves with it into the block
  group.
- parse html/emptyNestedCheckListItem: the paragraph is a child of the
  list item, not a new bullet.
- parse markdown/complex: "Paragraph" is a paragraph child of its list
  item, and the lists after it are children of the same list item. It
  was a new bullet that took these lists as its children.
- nestedLists.test.ts, "stays out of the active document": the image
  after the nested list is in the block group of the list item, not in
  a new <li>. The test still sees an element of the HTML that goes into
  the active document.
New cases in the parse tests (parseTestInstances.ts): 7 for HTML and 1
for markdown.

The new elements of the two steps are made in `detachedDoc()`.
No test failed when one of these rules of `nestedLists.ts` was removed.
Each new parse case fails without its rule:

- listItemEmptyParagraphBeforeContent: an empty paragraph is not the
  content of the list item (`hasContent` in `isTextBlock`).
- listItemTextAndBlockBeforeNestedList: the text before the first block
  is the content of the list item.
- listItemLinkedImageBeforeNestedList: an image is a block, also in a
  link (the last line of `BLOCK_ELEMENTS`, `querySelector` in `isBlock`).
- listItemHeadingCodeQuoteBeforeNestedList: a heading, a code block and
  a quote are text blocks (`isTextBlock`).
- listItemContentInDivBeforeNestedList: a first block that is not a text
  block stays in the list item (the last line of `childrenStart`).
- nestedListInOwnListItem, nestedCheckListInOwnListItem: a list item
  that holds only a nested list (the `start === 0` branch).
- nestedListInAndNextToListItem: a list next to a list item that has a
  block group of step 1 (the loop in `createGroups`).

The inputs are forms of Tiptap, Notion, GitHub, Plate and Lexical, and
of markdown renderers. Three cases fail on `main`:
listItemTextAndBlockBeforeNestedList,
listItemLinkedImageBeforeNestedList and
listItemHeadingCodeQuoteBeforeNestedList. The other five have the same
result on `main`. They are guards.

There is no source change.

This branch was successfully deployed

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

1 participant