@@ -77,10 +77,11 @@ export function getListItemContent(
7777
7878 // Structure above is `blockGroup<blockContainer<any>[]>`
7979 // We want to extract the first `blockContainer` node's content, and see if it is a text block.
80- const listItemsFirstChild = blockGroupNode . firstChild ?. firstChild ;
80+ const firstBlockContainer = blockGroupNode . firstChild ;
81+ const listItemsFirstChild = firstBlockContainer ?. firstChild ;
8182
8283 // If the first node is not a text block, then it's first child is not compatible with the list item node.
83- if ( ! listItemsFirstChild ?. isTextblock ) {
84+ if ( ! firstBlockContainer || ! listItemsFirstChild ?. isTextblock ) {
8485 // So, we do not try inserting anything into the list item, and instead return anything we found as children for the list item.
8586 return Fragment . from ( blockGroupNode ) ;
8687 }
@@ -93,11 +94,13 @@ export function getListItemContent(
9394 listItemsFirstChild . content ,
9495 ) ;
9596
96- // We have `blockGroup<listItemsFirstChild, ...blockContainer<any>[]>`
97- // We want to extract out the rest of the nodes as `<...blockContainer<any>[]>`
98- const remainingListItemChildren = blockGroupNode . content . cut (
99- // +2 for the `blockGroup` node's start and end markers
100- listItemsFirstChild . nodeSize + 2 ,
97+ // We have `blockGroup<blockContainer<listItemsFirstChild, blockGroup?>, ...blockContainer<any>[]>`
98+ // We want to extract out the rest of the nodes as `<...blockContainer<any>[]>`.
99+ // The first block's own children (e.g. a parsed `<details>` body) come first.
100+ const firstBlockChildren =
101+ firstBlockContainer . maybeChild ( 1 ) ?. content ?? Fragment . empty ;
102+ const remainingListItemChildren = firstBlockChildren . append (
103+ blockGroupNode . content . cut ( firstBlockContainer . nodeSize ) ,
101104 ) ;
102105 const hasRemainingListItemChildren = remainingListItemChildren . size > 0 ;
103106
0 commit comments