Skip to content

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

Merged
nperez0111 merged 3 commits into
fix/html-parse-detached-documentfrom
fix/html-list-item-children
Nov 27, 2026
Merged

nperez0111 merged 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.

Summary by CodeRabbit

  • Bug Fixes
    • Improved nested-list parsing so paragraphs, images, code, headings, quotes, and other content remain in the correct list item and order.
    • Improved numbered-list handling for nested items, including ordered lists with a specified starting number.
    • Preserved content following nested lists within its parent list item, rather than treating it as a separate item.

@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 26, 2026 2:46pm UTC
blocknote-website Ready Ready Preview Nov 26, 2026 2:46pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Nested-list parsing now places content after a nested list in the list item’s block group. The numbered-list parser also handles nested items represented by DIV elements and reads the ordered list’s start value from the OL ancestor.

Changes: Nested List Parsing

Layer / File(s) Summary
Nested content boundaries and grouping
packages/core/src/api/parsers/html/util/nestedLists.ts, packages/core/src/api/parsers/html/util/nestedLists.browser.test.ts, tests/src/integration/formatConversion/parse/parseTestInstances.ts
The parser locates where nested content begins, then moves the relevant children into a block group or replaces the list item. Grouping reuses an existing block group when present. Added parse cases cover nested lists with surrounding content and examples from several editor and export formats.
Ordered-list start handling
packages/core/src/blocks/ListItem/NumberedListItem/block.ts, tests/src/integration/formatConversion/parse/parseTestInstances.ts
For nested items represented by DIV elements, the parser reads the start attribute from the OL ancestor and checks the item’s previous sibling. An added parse case covers an ordered list with start="2" and nested lists.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Possibly related PRs

  • TypeCellOS/BlockNote#3404: This PR adds HTML preprocessing for nested-list parsing and describes list-item placement behavior that connects to the rules changed here.
  • TypeCellOS/BlockNote#3393: This stacked PR changes the DOM document used by parse helpers that this change also updates.
  • TypeCellOS/BlockNote#3388: This PR changes HTML export and parsing of toggle list items with list children, using nested-list placement behavior changed here.

Suggested reviewers: nperez0111

Merge Risk: Minimal · up to 586f0 · assessed changes only

Path filters excluded changed files. This rating applies only to the assessed changes.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the two changes in the PR: the numbered-list start and the children of a list item in the HTML parse. The changeset matches both. The title is specific and concise, and it names the sc…
Description check Passed The description follows the template sections: Summary, Testing, and Notes cover the change. It explains the two fixes, their causes, and the expected output. It reports 9 new HTML and Markdown parse …
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.
Full details: Title check

Explanation

The title names the two changes in the PR: the numbered-list start and the children of a list item in the HTML parse. The changeset matches both. The title is specific and concise, and it names the scope as core. It describes the main changes without file lists or vague terms.

Full details: Description check

Explanation

The description follows the template sections: Summary, Testing, and Notes cover the change. It explains the two fixes, their causes, and the expected output. It reports 9 new HTML and Markdown parse cases, 8 more list-item rule cases, changed snapshots, and test counts. The Rationale, Impact, Screenshots/Video, Checklist, and Additional Notes headings are missing. The Notes section partly covers Impact, but the template's Rationale and Impact are not labeled. The Checklist items are not ticked.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • 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

A rabbit reads each nested row,
And checks where trailing pictures go.
The list keeps blocks in proper place,
While numbered starts set the pace.
I nibble clover, hop, and cheer,
Clean parsing brings a carrot near.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1ab984be-d313-4304-8c07-07b691b6a306
Commits

Reviewing files that changed from the base of the PR and between f7b04c4 and 586f0cc.

Files ignored due to path filters: 20

  • packages/core/src/api/parsers/html/util/__snapshots__/nestedLists.browser.test.ts.snap is excluded by !**/*.snap, !**/__snapshots__/**
  • tests/src/integration/formatConversion/parse/__snapshots__/html/checkListItemBlocksAroundNestedList.json is excluded by !**/__snapshots__/**
  • tests/src/integration/formatConversion/parse/__snapshots__/html/emptyNestedCheckListItem.json is excluded by !**/__snapshots__/**
  • tests/src/integration/formatConversion/parse/__snapshots__/html/listItemBlockBeforeNestedList.json is excluded by !**/__snapshots__/**
  • tests/src/integration/formatConversion/parse/__snapshots__/html/listItemBlocksAroundNestedLists.json is excluded by !**/__snapshots__/**
  • tests/src/integration/formatConversion/parse/__snapshots__/html/listItemContentInDivBeforeNestedList.json is excluded by !**/__snapshots__/**
  • tests/src/integration/formatConversion/parse/__snapshots__/html/listItemEmptyNodeBeforeContent.json is excluded by !**/__snapshots__/**
  • tests/src/integration/formatConversion/parse/__snapshots__/html/listItemEmptyParagraphBeforeContent.json is excluded by !**/__snapshots__/**
  • tests/src/integration/formatConversion/parse/__snapshots__/html/listItemHeadingCodeQuoteBeforeNestedList.json is excluded by !**/__snapshots__/**
  • tests/src/integration/formatConversion/parse/__snapshots__/html/listItemImageAfterNestedList.json is excluded by !**/__snapshots__/**
  • tests/src/integration/formatConversion/parse/__snapshots__/html/listItemLinkedImageBeforeNestedList.json is excluded by !**/__snapshots__/**
  • tests/src/integration/formatConversion/parse/__snapshots__/html/listItemParagraphAfterNestedList.json is excluded by !**/__snapshots__/**
  • tests/src/integration/formatConversion/parse/__snapshots__/html/listItemTextAfterNestedList.json is excluded by !**/__snapshots__/**
  • tests/src/integration/formatConversion/parse/__snapshots__/html/listItemTextAndBlockBeforeNestedList.json is excluded by !**/__snapshots__/**
  • tests/src/integration/formatConversion/parse/__snapshots__/html/nestedCheckListInOwnListItem.json is excluded by !**/__snapshots__/**
  • tests/src/integration/formatConversion/parse/__snapshots__/html/nestedListInAndNextToListItem.json is excluded by !**/__snapshots__/**
  • tests/src/integration/formatConversion/parse/__snapshots__/html/nestedListInOwnListItem.json is excluded by !**/__snapshots__/**
  • tests/src/integration/formatConversion/parse/__snapshots__/html/orderedListStartWithNestedList.json is excluded by !**/__snapshots__/**
  • tests/src/integration/formatConversion/parse/__snapshots__/markdown/complex.json is excluded by !**/__snapshots__/**
  • tests/src/integration/formatConversion/parse/__snapshots__/markdown/listItemParagraphAfterNestedList.json is excluded by !**/__snapshots__/**
Files selected for processing: 1

  • tests/src/integration/formatConversion/parse/parseTestInstances.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

@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: 586f0cc

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
PR Preview Action v1.8.2
Preview removed because the pull request was closed.
2026-11-27 12:10 UTC

@YousefED
YousefED added this pull request to stack #3405 November 22, 2026 16:19
@YousefED
YousefED force-pushed the fix/html-list-item-children branch from 12bc606 to 1966327 Compare November 22, 2026 18:44
@YousefED
YousefED removed this pull request from stack #3405 November 22, 2026 18:44
@YousefED
YousefED changed the base branch from main to fix/html-parse-detached-document November 22, 2026 18:44
@YousefED
YousefED added this pull request to stack #3406 November 22, 2026 18:44
@YousefED
YousefED force-pushed the fix/html-list-item-children branch from 1966327 to 8aa5c57 Compare November 24, 2026 08:31
@YousefED
YousefED force-pushed the fix/html-list-item-children branch from 8aa5c57 to ff41820 Compare November 24, 2026 09:07
@YousefED
YousefED force-pushed the fix/html-list-item-children branch from ff41820 to e17a1bc Compare November 24, 2026 09:38
@YousefED
YousefED force-pushed the fix/html-list-item-children branch from e17a1bc to b065fc6 Compare November 24, 2026 11:28
@YousefED
YousefED force-pushed the fix/html-list-item-children branch from b065fc6 to f7b04c4 Compare November 25, 2026 08:08
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.browser.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.browser.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.
@nperez0111
nperez0111 force-pushed the fix/html-list-item-children branch from f7b04c4 to 586f0cc Compare November 26, 2026 14:43
@nperez0111
nperez0111 merged commit 586f0cc into main Nov 27, 2026
38 checks passed
@nperez0111
nperez0111 deleted the fix/html-list-item-children branch November 27, 2026 12:10
An error occurred while trying to automatically change base from fix/html-parse-detached-document to main November 27, 2026 12:30
YousefED added a commit that referenced this pull request Dec 3, 2026
main has 91 new commits. Most core conflicts come from core fixes of this
branch that went to main as separate pull requests, often in a changed form.
For these files, the form of main is the reviewed one.

Resolutions:
- y/extensions/blockMatchNodes.ts and its browser test, y/utils.ts and its
  test: the files of main (#3380: blocks pair by ID only).
- api/nodeConversions/blockToNode.ts: main (#3383).
- api/parsers/html/util/nestedLists.ts and its snapshot: main (#3393, #3404).
- blocks/File/block.ts, createLinkWithCaption.ts: main (#3401, #3387).
- blocks/Image, Video, Audio: main (#3400).
- CheckListItem/block.ts: main (#3388). NumberedListItem/block.ts: main
  (#3403).
- api/exporters/markdown/htmlToMarkdown.ts and
  api/parsers/markdown/markdownToHtml.ts: main (#3385, #3392, #3394, #3391
  and later commits). The parts of the branch that main does not have and
  that the lens needs come back in separate commits after this merge.
- markdownExporter.ts, parseMarkdown.ts, ExportManager.ts, copyExtension.ts,
  SideMenu/dragging.ts merged without a conflict, but they used the API of
  the old markdown files of the branch (`escapes`, `target`): main.
- serializeBlocksExternalHTML.ts merged without a conflict, but the merge
  had the toggle child order fix two times and did not compile: the form of
  main (#3388), with the white space placeholder of the branch.
- exportParseEqualityTestInstances.ts: main (the toggle case of #3388).
- vite.config.ts: main, with the lint rules of the lens.
- tests/vite.config.browser.ts: main, with the lens files.
- pnpm-lock.yaml: main, then `vp install`.

main moved the shared test document to tests/src/fixtures/exporters (#3420).
The lens test helper imports it from there, and the xl-ai build does not
include the lens test helpers and benchmarks (a package build cannot read a
file outside the package).

This branch was successfully deployed

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