3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-19 06:35:44 +01:00

Answer architecture round 2: itemParts takes one run of task lists over the item, the properties share blockTaskItemChildren, and readBlock's bullet case names who reads a task list first

This commit is contained in:
2026-10-09 14:20:36 +02:00
committed by Lillem4n
parent 2e640ded91
commit 180840532d
5 changed files with 21 additions and 31 deletions
+1
View File
@@ -121,6 +121,7 @@ function readBlock(block: ReadBlock, reading: Reading, path: ConvertErrorPath, d
case 'blockquote':
return reading.claims.alerts ? quoteNode(block.blocks, reading, path, depth) : containerNode({ type: 'blockquote' }, block.blocks, reading, path, depth)
case 'bulletList':
// readBlocks reads a portable task list before it reaches here.
return listNode({ type: 'bulletList' }, block.items, reading, path, depth)
case 'code':
return codeBlockNode(block.language, block.text, reading, path, depth)
+5 -6
View File
@@ -29,17 +29,16 @@ function itemsOf(children: readonly AdfNode[]): AdfNode[][] {
return items
}
// The item reads as one run: the task's blocks, then the children after it.
function itemParts(item: readonly AdfNode[]): { kept: AdfNode[]; rest: AdfNode[] } {
const [task] = item
const [task, ...after] = item
if (task === undefined || !isTaskItem(task)) return { kept: [], rest: [...item] }
const content = task.type === 'blockTaskItem' ? nodeContent(task) : []
const run = [...content, ...after]
const paragraphs = runEnd(content, 0, 'paragraph')
const nested = runEnd(content, paragraphs, 'taskList')
const unheld = content.slice(nested)
const after = item.slice(1)
const beside = unheld.length === 0 ? runEnd(after, 0, 'taskList') : 0
const nested = runEnd(run, paragraphs, 'taskList')
const head = task.type === 'blockTaskItem' ? taskOfParagraphs(task, content.slice(0, paragraphs)) : task
return { kept: [head, ...content.slice(paragraphs, nested), ...after.slice(0, beside)], rest: [...unheld, ...after.slice(beside)] }
return { kept: [head, ...run.slice(paragraphs, nested)], rest: run.slice(nested) }
}
function runEnd(nodes: readonly AdfNode[], start: number, type: string): number {