Merge pull request #1937 from MohammadHijjawi97/fix/blocknote-nested-numbered-lists

fix(export): number nested BlockNote lists on their own
This commit is contained in:
Rohan Verma 2026-09-28 15:55:01 -07:00 • committed by GitHub
commit d084e8bdef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 3 deletions

View file

@ -217,9 +217,12 @@ def _render_block(
# --- Render nested children (indented) ---
if children:
# Children form their own list: numbering starts over and must not
# leak into this block's siblings.
child_counter = 0
for child in children:
child_lines, numbered_list_counter = _render_block(
child, indent=indent + 1, numbered_list_counter=numbered_list_counter
child_lines, child_counter = _render_block(
child, indent=indent + 1, numbered_list_counter=child_counter
)
lines.extend(child_lines)

View file

@ -494,7 +494,24 @@ def test_mixed_deep_nested_children_indentation():
assert (
blocknote_to_markdown(test_block)
== f"- Parent\n{prefix}- Child 1\n{prefix * 2}1. Nested Child 1\n{prefix * 3}2. Nested Child 2\n{prefix}- Child 2\n{prefix}- Child 3"
== f"- Parent\n{prefix}- Child 1\n{prefix * 2}1. Nested Child 1\n{prefix * 3}1. Nested Child 2\n{prefix}- Child 2\n{prefix}- Child 3"
)
def test_nested_numbered_list_numbers_independently_of_parent():
"""A nested numbered list starts at 1 and leaves the parent list's count alone."""
def item(text, children=()):
return {
"type": "numberedListItem",
"content": [{"type": "text", "text": text}],
"children": list(children),
}
blocks = [item("First", [item("Sub A"), item("Sub B")]), item("Second")]
assert (
blocknote_to_markdown(blocks) == "1. First\n 1. Sub A\n 2. Sub B\n2. Second"
)