From 03c48948906b900d9fc49f18b84c1dd98f53d167 Mon Sep 17 00:00:00 2001 From: yousefed Date: Sat, 21 Nov 2026 20:24:25 +0100 Subject: [PATCH 1/3] fix(core): keep the list start when the first item has a nested list The fault: the HTML parse lost the `start` of a numbered list (for example `
    `) 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 `
  1. `. 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 `
    1. `. --- .../blocks/ListItem/NumberedListItem/block.ts | 11 ++- .../html/orderedListStartWithNestedList.json | 90 +++++++++++++++++++ .../parse/parseTestInstances.ts | 21 +++++ 3 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 tests/src/unit/core/formatConversion/parse/__snapshots__/html/orderedListStartWithNestedList.json diff --git a/packages/core/src/blocks/ListItem/NumberedListItem/block.ts b/packages/core/src/blocks/ListItem/NumberedListItem/block.ts index 57530d741b..beca47a7fa 100644 --- a/packages/core/src/blocks/ListItem/NumberedListItem/block.ts +++ b/packages/core/src/blocks/ListItem/NumberedListItem/block.ts @@ -52,11 +52,18 @@ export const createNumberedListItemBlockSpec = createBlockSpec( parent.tagName === "OL" || (parent.tagName === "DIV" && parent.parentElement?.tagName === "OL") ) { - const startIndex = parseInt(parent.getAttribute("start") || "1"); + // The parser puts an item with nested blocks into a `div`, together + // with the block group of these blocks (see `createGroups` in + // `nestedLists.ts`). Then that `div` has the place of the item in the + // list. + const item = parent.tagName === "DIV" ? parent : element; + const startIndex = parseInt( + item.parentElement?.getAttribute("start") || "1", + ); const defaultProps = parseDefaultProps(element); - if (element.previousElementSibling || startIndex === 1) { + if (item.previousElementSibling || startIndex === 1) { return defaultProps; } diff --git a/tests/src/unit/core/formatConversion/parse/__snapshots__/html/orderedListStartWithNestedList.json b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/orderedListStartWithNestedList.json new file mode 100644 index 0000000000..c534ad46e9 --- /dev/null +++ b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/orderedListStartWithNestedList.json @@ -0,0 +1,90 @@ +[ + { + "children": [ + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Nested Item 1", + "type": "text", + }, + ], + "id": "2", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + ], + "content": [ + { + "styles": {}, + "text": "List Item 2", + "type": "text", + }, + ], + "id": "1", + "props": { + "backgroundColor": "default", + "start": 2, + "textAlignment": "left", + "textColor": "default", + }, + "type": "numberedListItem", + }, + { + "children": [ + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Nested Item 2", + "type": "text", + }, + ], + "id": "4", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + ], + "content": [ + { + "styles": {}, + "text": "List Item 3", + "type": "text", + }, + ], + "id": "3", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "numberedListItem", + }, + { + "children": [], + "content": [ + { + "styles": {}, + "text": "List Item 4", + "type": "text", + }, + ], + "id": "5", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "numberedListItem", + }, +] \ No newline at end of file diff --git a/tests/src/unit/core/formatConversion/parse/parseTestInstances.ts b/tests/src/unit/core/formatConversion/parse/parseTestInstances.ts index 33f4be5e4d..18a8c8e027 100644 --- a/tests/src/unit/core/formatConversion/parse/parseTestInstances.ts +++ b/tests/src/unit/core/formatConversion/parse/parseTestInstances.ts @@ -913,6 +913,27 @@ console.log("Third Line")`,
    2. List Item 2
    3. List Item 3
    4. List Item 4
    5. +
    `, + }, + executeTest: testParseHTML, + }, + // Only the first item gets the start of the list, also if items have a + // nested list. + { + testCase: { + name: "orderedListStartWithNestedList", + content: `
      +
    1. List Item 2 +
        +
      • Nested Item 1
      • +
      +
    2. +
    3. List Item 3 +
        +
      • Nested Item 2
      • +
      +
    4. +
    5. List Item 4
    `, }, executeTest: testParseHTML, From 3dff9fa5dc257de06c417c67f679367d00b7ecb5 Mon Sep 17 00:00:00 2001 From: yousefed Date: Sat, 21 Nov 2026 20:24:41 +0100 Subject: [PATCH 2/3] fix(core): the children of a list item stay in the list item The HTML parse moves a nested list out of its
  2. , to make it a child block of the list item. It did not keep the other nodes of the
  3. 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
  4. 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
  5. , 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 `
  6. a

    b
  7. `). A
  8. 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
  9. . 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
  10. . 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()`. --- .../__snapshots__/nestedLists.test.ts.snap | 26 ++- .../api/parsers/html/util/nestedLists.test.ts | 5 +- .../src/api/parsers/html/util/nestedLists.ts | 142 +++++++++++--- .../checkListItemBlocksAroundNestedList.json | 55 ++++++ .../html/emptyNestedCheckListItem.json | 34 ++-- .../html/listItemBlockBeforeNestedList.json | 69 +++++++ .../html/listItemBlocksAroundNestedLists.json | 122 ++++++++++++ .../html/listItemEmptyNodeBeforeContent.json | 177 ++++++++++++++++++ .../html/listItemImageAfterNestedList.json | 68 +++++++ .../listItemParagraphAfterNestedList.json | 71 +++++++ .../html/listItemTextAfterNestedList.json | 78 ++++++++ .../parse/__snapshots__/markdown/complex.json | 35 ++-- .../listItemParagraphAfterNestedList.json | 71 +++++++ .../parse/parseTestInstances.ts | 89 +++++++++ 14 files changed, 966 insertions(+), 76 deletions(-) create mode 100644 tests/src/unit/core/formatConversion/parse/__snapshots__/html/checkListItemBlocksAroundNestedList.json create mode 100644 tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemBlockBeforeNestedList.json create mode 100644 tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemBlocksAroundNestedLists.json create mode 100644 tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemEmptyNodeBeforeContent.json create mode 100644 tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemImageAfterNestedList.json create mode 100644 tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemParagraphAfterNestedList.json create mode 100644 tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemTextAfterNestedList.json create mode 100644 tests/src/unit/core/formatConversion/parse/__snapshots__/markdown/listItemParagraphAfterNestedList.json diff --git a/packages/core/src/api/parsers/html/util/__snapshots__/nestedLists.test.ts.snap b/packages/core/src/api/parsers/html/util/__snapshots__/nestedLists.test.ts.snap index 1db488255b..d9e81112b2 100644 --- a/packages/core/src/api/parsers/html/util/__snapshots__/nestedLists.test.ts.snap +++ b/packages/core/src/api/parsers/html/util/__snapshots__/nestedLists.test.ts.snap @@ -11,14 +11,16 @@ exports[`Lift nested lists > Lifts multiple bullet lists 1`] = `
  11. Nested Bullet List Item 2
  12. - + + +
  13. Bullet List Item 2
  14. @@ -36,16 +38,17 @@ exports[`Lift nested lists > Lifts multiple bullet lists with content in between
  15. Nested Bullet List Item 2
  16. -
  17. + In between content -
    • +
      • Nested Bullet List Item 3
      • Nested Bullet List Item 4
      • -
    + +
  18. Bullet List Item 2
  19. @@ -63,7 +66,8 @@ exports[`Lift nested lists > Lifts nested bullet lists 1`] = `
  20. Nested Bullet List Item 2
  21. - + +
  22. Bullet List Item 2
  23. @@ -81,9 +85,9 @@ exports[`Lift nested lists > Lifts nested bullet lists with content after nested
  24. Nested Bullet List Item 2
  25. -
  26. + More content in list item 1 -
  27. +
  28. Bullet List Item 2
  29. @@ -118,7 +122,8 @@ exports[`Lift nested lists > Lifts nested mixed lists 1`] = `
  30. Bullet List Item 2
  31. - + +
  32. Numbered List Item 2
  33. @@ -136,7 +141,8 @@ exports[`Lift nested lists > Lifts nested numbered lists 1`] = `
  34. Nested Numbered List Item 2
  35. -
+ +
  • Numbered List Item 2
  • diff --git a/packages/core/src/api/parsers/html/util/nestedLists.test.ts b/packages/core/src/api/parsers/html/util/nestedLists.test.ts index e88c859784..6ee15c077d 100644 --- a/packages/core/src/api/parsers/html/util/nestedLists.test.ts +++ b/packages/core/src/api/parsers/html/util/nestedLists.test.ts @@ -196,9 +196,10 @@ describe("content after a nested list", () => { ``, ); - // The content after the nested list is in a list item of its own. + // The content after the nested list is a child of the list item: it is in + // the block group, after the nested list. expect(htmlNode.innerHTML).toMatchInlineSnapshot( - `""`, + `""`, ); expect(inActiveDocument).toEqual([]); }); diff --git a/packages/core/src/api/parsers/html/util/nestedLists.ts b/packages/core/src/api/parsers/html/util/nestedLists.ts index e683db2e41..7b3f967c42 100644 --- a/packages/core/src/api/parsers/html/util/nestedLists.ts +++ b/packages/core/src/api/parsers/html/util/nestedLists.ts @@ -1,11 +1,76 @@ import { detachedDoc } from "../../../../util/detachedDoc.js"; -function getChildIndex(node: Element) { - return Array.prototype.indexOf.call(node.parentElement!.childNodes, node); +function isElement(node: Node): node is Element { + return node.nodeType === 1; } -function isWhitespaceNode(node: Node) { - return node.nodeType === 3 && !/\S/.test(node.nodeValue || ""); +function isList(node: Node) { + return node.nodeName === "UL" || node.nodeName === "OL"; +} + +// The elements that end a paragraph in the parse. These are the block elements +// of the ProseMirror DOM parser, and the elements that BlockNote parses as a +// block (the last line). The first three lines are a copy of `blockTags`, which +// prosemirror-model does not export: +// https://github.com/ProseMirror/prosemirror-model/blob/master/src/from_dom.ts +const BLOCK_ELEMENTS = [ + "address, article, aside, blockquote, body, canvas, dd, div, dl, fieldset", + "figcaption, figure, footer, form, h1, h2, h3, h4, h5, h6, header, hgroup", + "hr, li, noscript, ol, output, p, pre, section, table, tfoot, ul", + "audio, details, embed, img, video", +].join(", "); + +/** True for a block element, and for an element that has a block in it. */ +function isBlock(node: Node) { + return ( + isElement(node) && + (node.matches(BLOCK_ELEMENTS) || + node.querySelector(BLOCK_ELEMENTS) !== null) + ); +} + +/** + * True for text and for an element with text. These nodes give no content in + * the parse: white space, a comment (node type 8), and an element without text + * (for example an anchor, or the check box of a check list item). + */ +function hasContent(node: Node) { + return node.nodeType !== 8 && /\S/.test(node.textContent || ""); +} + +/** + * True for an element that the parse reads as one block with text: a + * paragraph, a heading, a code block or a quote. + */ +function isTextBlock(node: Node) { + return /^(P|H[1-6]|PRE|BLOCKQUOTE)$/.test(node.nodeName) && hasContent(node); +} + +/** + * Returns the index of the first child in the nodes of a list item that has a + * nested list. The nodes before it are the own content of the list item: its + * text and inline elements up to the first block, or else that first block, if + * it is a block with text. + * + * If the first block is not a block with text (for example an image, or the + * nested list), the nodes before the nested list stay in the list item. The + * parse of the list item (`getListItemContent`) then finds its content. + */ +function childrenStart(nodes: Node[]) { + const firstBlock = nodes.findIndex(isBlock); + if (nodes.slice(0, firstBlock).some(hasContent)) { + return firstBlock; + } + if (isTextBlock(nodes[firstBlock])) { + return firstBlock + 1; + } + return nodes.findIndex(isList); +} + +function createBlockGroup() { + const blockGroup = detachedDoc().createElement("div"); + blockGroup.setAttribute("data-node-type", "blockGroup"); + return blockGroup; } /** @@ -29,32 +94,48 @@ function isWhitespaceNode(node: Node) { * * * + * A list item with content of its own keeps that content. All the nodes after + * it are the children of the list item. They move out of the list item into a + * block group, in order: + * + *
  • + *

    item

    + *
    ...
    + * + * text + *
  • + * + * Into: + *
  • item

  • + *
    + *
    ...
    + * + * text + *
    + * */ function liftNestedListsToParent(element: HTMLElement) { element.querySelectorAll("li > ul, li > ol").forEach((list) => { - const index = getChildIndex(list); const parentListItem = list.parentElement!; - const siblingsAfter = Array.from(parentListItem.childNodes).slice( - index + 1, - ); - list.remove(); - siblingsAfter.forEach((sibling) => { - sibling.remove(); - }); - - parentListItem.insertAdjacentElement("afterend", list); - - siblingsAfter.reverse().forEach((sibling) => { - if (isWhitespaceNode(sibling)) { - return; - } - const siblingContainer = detachedDoc().createElement("li"); - siblingContainer.append(sibling); - list.insertAdjacentElement("afterend", siblingContainer); - }); - if (parentListItem.childNodes.length === 0) { - parentListItem.remove(); + // An earlier list of the same list item moved this list out already. + if (parentListItem.nodeName !== "LI") { + return; } + + const nodes = Array.from(parentListItem.childNodes); + const start = childrenStart(nodes); + const children = nodes.slice(start); + + if (start === 0) { + // The list item starts with the nested list. Its nodes take its place, + // and step 2 gives the nested list to the list item before it. + parentListItem.replaceWith(...children); + return; + } + + const blockGroup = createBlockGroup(); + parentListItem.after(blockGroup); + blockGroup.append(...children); }); } @@ -78,18 +159,21 @@ function liftNestedListsToParent(element: HTMLElement) { * * * + * If step 1 made a block group for the list item, that block group is used. + * * This resulting format is parsed */ function createGroups(element: HTMLElement) { - element.querySelectorAll("li + ul, li + ol").forEach((list) => { - const listItem = list.previousElementSibling as HTMLElement; + const firstChildren = + 'li + ul, li + ol, li + div[data-node-type="blockGroup"]'; + element.querySelectorAll(firstChildren).forEach((firstChild) => { + const listItem = firstChild.previousElementSibling as HTMLElement; const blockContainer = detachedDoc().createElement("div"); listItem.insertAdjacentElement("afterend", blockContainer); blockContainer.append(listItem); - const blockGroup = detachedDoc().createElement("div"); - blockGroup.setAttribute("data-node-type", "blockGroup"); + const blockGroup = isList(firstChild) ? createBlockGroup() : firstChild; blockContainer.append(blockGroup); while ( diff --git a/tests/src/unit/core/formatConversion/parse/__snapshots__/html/checkListItemBlocksAroundNestedList.json b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/checkListItemBlocksAroundNestedList.json new file mode 100644 index 0000000000..80090261e2 --- /dev/null +++ b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/checkListItemBlocksAroundNestedList.json @@ -0,0 +1,55 @@ +[ + { + "children": [ + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Nested", + "type": "text", + }, + ], + "id": "2", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + { + "children": [], + "content": [ + { + "styles": {}, + "text": "After", + "type": "text", + }, + ], + "id": "3", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "paragraph", + }, + ], + "content": [ + { + "styles": {}, + "text": "Item 1", + "type": "text", + }, + ], + "id": "1", + "props": { + "backgroundColor": "default", + "checked": true, + "textAlignment": "left", + "textColor": "default", + }, + "type": "checkListItem", + }, +] \ No newline at end of file diff --git a/tests/src/unit/core/formatConversion/parse/__snapshots__/html/emptyNestedCheckListItem.json b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/emptyNestedCheckListItem.json index f98bf7027f..756f3ab988 100644 --- a/tests/src/unit/core/formatConversion/parse/__snapshots__/html/emptyNestedCheckListItem.json +++ b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/emptyNestedCheckListItem.json @@ -13,26 +13,26 @@ }, "type": "checkListItem", }, - ], - "content": [], - "id": "1", - "props": { - "backgroundColor": "default", - "textAlignment": "left", - "textColor": "default", - }, - "type": "bulletListItem", - }, - { - "children": [], - "content": [ { - "styles": {}, - "text": "Paragraph", - "type": "text", + "children": [], + "content": [ + { + "styles": {}, + "text": "Paragraph", + "type": "text", + }, + ], + "id": "3", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "paragraph", }, ], - "id": "3", + "content": [], + "id": "1", "props": { "backgroundColor": "default", "textAlignment": "left", diff --git a/tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemBlockBeforeNestedList.json b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemBlockBeforeNestedList.json new file mode 100644 index 0000000000..b5246b77d2 --- /dev/null +++ b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemBlockBeforeNestedList.json @@ -0,0 +1,69 @@ +[ + { + "children": [ + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Code", + "type": "text", + }, + ], + "id": "2", + "props": { + "language": "javascript", + }, + "type": "codeBlock", + }, + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Nested", + "type": "text", + }, + ], + "id": "3", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + ], + "content": [ + { + "styles": {}, + "text": "Item 1", + "type": "text", + }, + ], + "id": "1", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Item 2", + "type": "text", + }, + ], + "id": "4", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, +] \ No newline at end of file diff --git a/tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemBlocksAroundNestedLists.json b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemBlocksAroundNestedLists.json new file mode 100644 index 0000000000..0c8591235a --- /dev/null +++ b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemBlocksAroundNestedLists.json @@ -0,0 +1,122 @@ +[ + { + "children": [ + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Before", + "type": "text", + }, + ], + "id": "2", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "paragraph", + }, + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Nested 1", + "type": "text", + }, + ], + "id": "3", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Between", + "type": "text", + }, + ], + "id": "4", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "paragraph", + }, + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Nested 2", + "type": "text", + }, + ], + "id": "5", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "numberedListItem", + }, + { + "children": [], + "content": [ + { + "styles": {}, + "text": "After", + "type": "text", + }, + ], + "id": "6", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "paragraph", + }, + ], + "content": [ + { + "styles": {}, + "text": "Item 1", + "type": "text", + }, + ], + "id": "1", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "numberedListItem", + }, + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Item 2", + "type": "text", + }, + ], + "id": "7", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "numberedListItem", + }, +] \ No newline at end of file diff --git a/tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemEmptyNodeBeforeContent.json b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemEmptyNodeBeforeContent.json new file mode 100644 index 0000000000..2d61d9f3e0 --- /dev/null +++ b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemEmptyNodeBeforeContent.json @@ -0,0 +1,177 @@ +[ + { + "children": [ + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Nested 1", + "type": "text", + }, + ], + "id": "2", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + ], + "content": [ + { + "styles": {}, + "text": "Item 1", + "type": "text", + }, + ], + "id": "1", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + { + "children": [ + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Nested 2", + "type": "text", + }, + ], + "id": "4", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + ], + "content": [ + { + "styles": {}, + "text": "Item 2", + "type": "text", + }, + ], + "id": "3", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + { + "children": [ + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Nested 3", + "type": "text", + }, + ], + "id": "6", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + ], + "content": [ + { + "styles": {}, + "text": "Item 3", + "type": "text", + }, + ], + "id": "5", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + { + "children": [ + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Nested 4", + "type": "text", + }, + ], + "id": "8", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + ], + "content": [ + { + "styles": {}, + "text": "Item 4", + "type": "text", + }, + ], + "id": "7", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + { + "children": [ + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Nested 5", + "type": "text", + }, + ], + "id": "10", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + ], + "content": [ + { + "styles": {}, + "text": "Item 5", + "type": "text", + }, + ], + "id": "9", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, +] \ No newline at end of file diff --git a/tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemImageAfterNestedList.json b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemImageAfterNestedList.json new file mode 100644 index 0000000000..ca2aefb695 --- /dev/null +++ b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemImageAfterNestedList.json @@ -0,0 +1,68 @@ +[ + { + "children": [ + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Nested", + "type": "text", + }, + ], + "id": "2", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + { + "children": [], + "content": undefined, + "id": "3", + "props": { + "backgroundColor": "default", + "caption": "", + "name": "", + "showPreview": true, + "textAlignment": "left", + "url": "exampleURL", + }, + "type": "image", + }, + ], + "content": [ + { + "styles": {}, + "text": "Item 1", + "type": "text", + }, + ], + "id": "1", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Item 2", + "type": "text", + }, + ], + "id": "4", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, +] \ No newline at end of file diff --git a/tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemParagraphAfterNestedList.json b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemParagraphAfterNestedList.json new file mode 100644 index 0000000000..46259dd67e --- /dev/null +++ b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemParagraphAfterNestedList.json @@ -0,0 +1,71 @@ +[ + { + "children": [ + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Nested", + "type": "text", + }, + ], + "id": "2", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + { + "children": [], + "content": [ + { + "styles": {}, + "text": "After", + "type": "text", + }, + ], + "id": "3", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "paragraph", + }, + ], + "content": [ + { + "styles": {}, + "text": "Item 1", + "type": "text", + }, + ], + "id": "1", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Item 2", + "type": "text", + }, + ], + "id": "4", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, +] \ No newline at end of file diff --git a/tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemTextAfterNestedList.json b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemTextAfterNestedList.json new file mode 100644 index 0000000000..118b321ba2 --- /dev/null +++ b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemTextAfterNestedList.json @@ -0,0 +1,78 @@ +[ + { + "children": [ + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Nested", + "type": "text", + }, + ], + "id": "2", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + { + "children": [], + "content": [ + { + "styles": {}, + "text": " After ", + "type": "text", + }, + { + "styles": { + "bold": true, + }, + "text": "bold", + "type": "text", + }, + ], + "id": "3", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "paragraph", + }, + ], + "content": [ + { + "styles": {}, + "text": "Item 1", + "type": "text", + }, + ], + "id": "1", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Item 2", + "type": "text", + }, + ], + "id": "4", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, +] \ No newline at end of file diff --git a/tests/src/unit/core/formatConversion/parse/__snapshots__/markdown/complex.json b/tests/src/unit/core/formatConversion/parse/__snapshots__/markdown/complex.json index 8f30c274ae..18c925e2c5 100644 --- a/tests/src/unit/core/formatConversion/parse/__snapshots__/markdown/complex.json +++ b/tests/src/unit/core/formatConversion/parse/__snapshots__/markdown/complex.json @@ -261,24 +261,23 @@ }, "type": "bulletListItem", }, - ], - "content": [ { - "styles": {}, - "text": "Bullet List Item", - "type": "text", + "children": [], + "content": [ + { + "styles": {}, + "text": "Paragraph", + "type": "text", + }, + ], + "id": "17", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "paragraph", }, - ], - "id": "15", - "props": { - "backgroundColor": "default", - "textAlignment": "left", - "textColor": "default", - }, - "type": "bulletListItem", - }, - { - "children": [ { "children": [], "content": [ @@ -369,11 +368,11 @@ "content": [ { "styles": {}, - "text": "Paragraph", + "text": "Bullet List Item", "type": "text", }, ], - "id": "17", + "id": "15", "props": { "backgroundColor": "default", "textAlignment": "left", diff --git a/tests/src/unit/core/formatConversion/parse/__snapshots__/markdown/listItemParagraphAfterNestedList.json b/tests/src/unit/core/formatConversion/parse/__snapshots__/markdown/listItemParagraphAfterNestedList.json new file mode 100644 index 0000000000..46259dd67e --- /dev/null +++ b/tests/src/unit/core/formatConversion/parse/__snapshots__/markdown/listItemParagraphAfterNestedList.json @@ -0,0 +1,71 @@ +[ + { + "children": [ + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Nested", + "type": "text", + }, + ], + "id": "2", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + { + "children": [], + "content": [ + { + "styles": {}, + "text": "After", + "type": "text", + }, + ], + "id": "3", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "paragraph", + }, + ], + "content": [ + { + "styles": {}, + "text": "Item 1", + "type": "text", + }, + ], + "id": "1", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Item 2", + "type": "text", + }, + ], + "id": "4", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, +] \ No newline at end of file diff --git a/tests/src/unit/core/formatConversion/parse/parseTestInstances.ts b/tests/src/unit/core/formatConversion/parse/parseTestInstances.ts index 18a8c8e027..427cec4cd2 100644 --- a/tests/src/unit/core/formatConversion/parse/parseTestInstances.ts +++ b/tests/src/unit/core/formatConversion/parse/parseTestInstances.ts @@ -385,6 +385,80 @@ export const parseTestInstancesHTML: TestInstance<

    Bullet List Item

  • Bullet List Item
  • +`, + }, + executeTest: testParseHTML, + }, + // The cases below are for a list item with a nested list and other blocks. + // All the blocks stay in the list item, in the order of the HTML. + { + testCase: { + name: "listItemParagraphAfterNestedList", + content: ``, + }, + executeTest: testParseHTML, + }, + // The text after the nested list is a paragraph. It keeps one space of the + // HTML source at its start, as each text after a block does in the parse. + { + testCase: { + name: "listItemTextAfterNestedList", + content: ``, + }, + executeTest: testParseHTML, + }, + { + testCase: { + name: "listItemImageAfterNestedList", + content: ``, + }, + executeTest: testParseHTML, + }, + { + testCase: { + name: "listItemBlockBeforeNestedList", + content: ``, + }, + executeTest: testParseHTML, + }, + { + testCase: { + name: "listItemBlocksAroundNestedLists", + content: `
    1. Item 1

      Before

      • Nested 1

      Between

      1. Nested 2

      After

    2. Item 2

    `, + }, + executeTest: testParseHTML, + }, + { + testCase: { + name: "checkListItemBlocksAroundNestedList", + content: ``, + }, + executeTest: testParseHTML, + }, + // A comment or an empty element before the content of a list item is not + // the content of the list item. + { + testCase: { + name: "listItemEmptyNodeBeforeContent", + content: ``, }, executeTest: testParseHTML, @@ -1291,6 +1365,21 @@ Paragraph * Bullet List Item 1. Numbered List Item +`, + }, + executeTest: testParseMarkdown, + }, + // The paragraph after the nested list stays in its list item. + { + testCase: { + name: "listItemParagraphAfterNestedList", + content: `* Item 1 + + * Nested + + After + +* Item 2 `, }, executeTest: testParseMarkdown, From 196632768b055dd656de48690fb9116aedebb69f Mon Sep 17 00:00:00 2001 From: yousefed Date: Sun, 22 Nov 2026 17:07:39 +0100 Subject: [PATCH 3/3] test(core): cover the list item rules of the HTML parse 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. --- .../listItemContentInDivBeforeNestedList.json | 37 ++++ .../listItemEmptyParagraphBeforeContent.json | 37 ++++ ...tItemHeadingCodeQuoteBeforeNestedList.json | 158 ++++++++++++++++++ .../listItemLinkedImageBeforeNestedList.json | 51 ++++++ .../listItemTextAndBlockBeforeNestedList.json | 54 ++++++ .../html/nestedCheckListInOwnListItem.json | 57 +++++++ .../html/nestedListInAndNextToListItem.json | 54 ++++++ .../html/nestedListInOwnListItem.json | 54 ++++++ .../parse/parseTestInstances.ts | 84 ++++++++++ 9 files changed, 586 insertions(+) create mode 100644 tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemContentInDivBeforeNestedList.json create mode 100644 tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemEmptyParagraphBeforeContent.json create mode 100644 tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemHeadingCodeQuoteBeforeNestedList.json create mode 100644 tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemLinkedImageBeforeNestedList.json create mode 100644 tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemTextAndBlockBeforeNestedList.json create mode 100644 tests/src/unit/core/formatConversion/parse/__snapshots__/html/nestedCheckListInOwnListItem.json create mode 100644 tests/src/unit/core/formatConversion/parse/__snapshots__/html/nestedListInAndNextToListItem.json create mode 100644 tests/src/unit/core/formatConversion/parse/__snapshots__/html/nestedListInOwnListItem.json diff --git a/tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemContentInDivBeforeNestedList.json b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemContentInDivBeforeNestedList.json new file mode 100644 index 0000000000..f99d36f46c --- /dev/null +++ b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemContentInDivBeforeNestedList.json @@ -0,0 +1,37 @@ +[ + { + "children": [ + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Nested", + "type": "text", + }, + ], + "id": "2", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + ], + "content": [ + { + "styles": {}, + "text": "Item 1", + "type": "text", + }, + ], + "id": "1", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, +] \ No newline at end of file diff --git a/tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemEmptyParagraphBeforeContent.json b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemEmptyParagraphBeforeContent.json new file mode 100644 index 0000000000..f99d36f46c --- /dev/null +++ b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemEmptyParagraphBeforeContent.json @@ -0,0 +1,37 @@ +[ + { + "children": [ + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Nested", + "type": "text", + }, + ], + "id": "2", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + ], + "content": [ + { + "styles": {}, + "text": "Item 1", + "type": "text", + }, + ], + "id": "1", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, +] \ No newline at end of file diff --git a/tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemHeadingCodeQuoteBeforeNestedList.json b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemHeadingCodeQuoteBeforeNestedList.json new file mode 100644 index 0000000000..3d2b5d2465 --- /dev/null +++ b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemHeadingCodeQuoteBeforeNestedList.json @@ -0,0 +1,158 @@ +[ + { + "children": [ + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Child 1", + "type": "text", + }, + ], + "id": "2", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "paragraph", + }, + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Nested 1", + "type": "text", + }, + ], + "id": "3", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + ], + "content": [ + { + "styles": {}, + "text": "Heading", + "type": "text", + }, + ], + "id": "1", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + { + "children": [ + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Child 2", + "type": "text", + }, + ], + "id": "5", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "paragraph", + }, + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Nested 2", + "type": "text", + }, + ], + "id": "6", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + ], + "content": [ + { + "styles": {}, + "text": "Code", + "type": "text", + }, + ], + "id": "4", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + { + "children": [ + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Child 3", + "type": "text", + }, + ], + "id": "8", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "paragraph", + }, + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Nested 3", + "type": "text", + }, + ], + "id": "9", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + ], + "content": [ + { + "styles": {}, + "text": "Quote", + "type": "text", + }, + ], + "id": "7", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, +] \ No newline at end of file diff --git a/tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemLinkedImageBeforeNestedList.json b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemLinkedImageBeforeNestedList.json new file mode 100644 index 0000000000..8bc60f3a4f --- /dev/null +++ b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemLinkedImageBeforeNestedList.json @@ -0,0 +1,51 @@ +[ + { + "children": [ + { + "children": [], + "content": undefined, + "id": "2", + "props": { + "backgroundColor": "default", + "caption": "", + "name": "alt", + "showPreview": true, + "textAlignment": "left", + "url": "https://example.com/image.png", + }, + "type": "image", + }, + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Nested", + "type": "text", + }, + ], + "id": "3", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + ], + "content": [ + { + "styles": {}, + "text": "Item 1", + "type": "text", + }, + ], + "id": "1", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, +] \ No newline at end of file diff --git a/tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemTextAndBlockBeforeNestedList.json b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemTextAndBlockBeforeNestedList.json new file mode 100644 index 0000000000..11a3d63913 --- /dev/null +++ b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/listItemTextAndBlockBeforeNestedList.json @@ -0,0 +1,54 @@ +[ + { + "children": [ + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Child", + "type": "text", + }, + ], + "id": "2", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "paragraph", + }, + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Nested", + "type": "text", + }, + ], + "id": "3", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + ], + "content": [ + { + "styles": {}, + "text": "Item 1", + "type": "text", + }, + ], + "id": "1", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, +] \ No newline at end of file diff --git a/tests/src/unit/core/formatConversion/parse/__snapshots__/html/nestedCheckListInOwnListItem.json b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/nestedCheckListInOwnListItem.json new file mode 100644 index 0000000000..db9d68cf82 --- /dev/null +++ b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/nestedCheckListInOwnListItem.json @@ -0,0 +1,57 @@ +[ + { + "children": [ + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Nested", + "type": "text", + }, + ], + "id": "2", + "props": { + "backgroundColor": "default", + "checked": false, + "textAlignment": "left", + "textColor": "default", + }, + "type": "checkListItem", + }, + ], + "content": [ + { + "styles": {}, + "text": "Item 1", + "type": "text", + }, + ], + "id": "1", + "props": { + "backgroundColor": "default", + "checked": true, + "textAlignment": "left", + "textColor": "default", + }, + "type": "checkListItem", + }, + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Item 2", + "type": "text", + }, + ], + "id": "3", + "props": { + "backgroundColor": "default", + "checked": false, + "textAlignment": "left", + "textColor": "default", + }, + "type": "checkListItem", + }, +] \ No newline at end of file diff --git a/tests/src/unit/core/formatConversion/parse/__snapshots__/html/nestedListInAndNextToListItem.json b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/nestedListInAndNextToListItem.json new file mode 100644 index 0000000000..1e4ed87ee0 --- /dev/null +++ b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/nestedListInAndNextToListItem.json @@ -0,0 +1,54 @@ +[ + { + "children": [ + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Nested 1", + "type": "text", + }, + ], + "id": "2", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Nested 2", + "type": "text", + }, + ], + "id": "3", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + ], + "content": [ + { + "styles": {}, + "text": "Item 1", + "type": "text", + }, + ], + "id": "1", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, +] \ No newline at end of file diff --git a/tests/src/unit/core/formatConversion/parse/__snapshots__/html/nestedListInOwnListItem.json b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/nestedListInOwnListItem.json new file mode 100644 index 0000000000..460e19bf88 --- /dev/null +++ b/tests/src/unit/core/formatConversion/parse/__snapshots__/html/nestedListInOwnListItem.json @@ -0,0 +1,54 @@ +[ + { + "children": [ + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Nested", + "type": "text", + }, + ], + "id": "2", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + ], + "content": [ + { + "styles": {}, + "text": "Item 1", + "type": "text", + }, + ], + "id": "1", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, + { + "children": [], + "content": [ + { + "styles": {}, + "text": "Item 2", + "type": "text", + }, + ], + "id": "3", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "textColor": "default", + }, + "type": "bulletListItem", + }, +] \ No newline at end of file diff --git a/tests/src/unit/core/formatConversion/parse/parseTestInstances.ts b/tests/src/unit/core/formatConversion/parse/parseTestInstances.ts index 427cec4cd2..f907e0a38b 100644 --- a/tests/src/unit/core/formatConversion/parse/parseTestInstances.ts +++ b/tests/src/unit/core/formatConversion/parse/parseTestInstances.ts @@ -463,6 +463,90 @@ export const parseTestInstancesHTML: TestInstance< }, executeTest: testParseHTML, }, + // An empty paragraph before the content of a list item is not the content + // of the list item. Tiptap writes this form for an empty first line. + { + testCase: { + name: "listItemEmptyParagraphBeforeContent", + content: ``, + }, + executeTest: testParseHTML, + }, + // The HTML export of Notion: the text of the list item is directly in the + // `
  • `, and a child block comes after it. + { + testCase: { + name: "listItemTextAndBlockBeforeNestedList", + content: `
    • Item 1

      Child

      • Nested
    `, + }, + executeTest: testParseHTML, + }, + // GitHub puts an image into a link. The image is a block, thus the text + // before the link is the content of the list item. + { + testCase: { + name: "listItemLinkedImageBeforeNestedList", + content: `
      +
    • Item 1 alt +
        +
      • Nested
      • +
      +
    • +
    `, + }, + executeTest: testParseHTML, + }, + // A markdown renderer writes these forms for a list item that starts with a + // heading, a code block or a quote. + { + testCase: { + name: "listItemHeadingCodeQuoteBeforeNestedList", + content: `
      +
    • Heading

      Child 1

      • Nested 1
    • +
    • Code

      Child 2

      • Nested 2
    • +
    • Quote

      Child 3

      • Nested 3
    • +
    `, + }, + executeTest: testParseHTML, + }, + // Plate puts the content of a list item into a `div`. The `div` is not the + // first child block of the list item. + { + testCase: { + name: "listItemContentInDivBeforeNestedList", + content: `
    • Item 1
      • Nested
    `, + }, + executeTest: testParseHTML, + }, + // Lexical puts a nested list into a list item of its own. The nested list + // goes to the list item before it. + { + testCase: { + name: "nestedListInOwnListItem", + content: `
    • Item 1
      • Nested
    • Item 2
    `, + }, + executeTest: testParseHTML, + }, + // The same form with check boxes. Lexical writes the check state as + // `aria-checked`, which the parser does not read. Thus this case has `input` + // elements. + { + testCase: { + name: "nestedCheckListInOwnListItem", + content: `
    • Item 1
      • Nested
    • Item 2
    `, + }, + executeTest: testParseHTML, + }, + // A nested list in the list item, and a list next to the list item (the + // form of Google Docs). Both are children of the list item. No known tool + // writes the two forms together. + { + testCase: { + name: "nestedListInAndNextToListItem", + content: `
    • Item 1
      • Nested 1
      • Nested 2
    `, + }, + executeTest: testParseHTML, + }, { testCase: { name: "textTableCell",