3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-13 04:08:29 +01:00

Answer prose round 1: a task item keeps the task lists right after its paragraphs nested, and the README, changelog, decision, comment, item 49 and a test title say it plainly

This commit is contained in:
2026-10-09 13:27:40 +02:00
committed by Lillem4n
parent 0c56a479bb
commit cd6cb8bece
9 changed files with 32 additions and 28 deletions
+1 -5
View File
@@ -198,7 +198,6 @@ function filledNode(node: AdfNode, content: Result<AdfNode[]>): Result<AdfNode>
return success({ ...node, content: content.value.length === 0 ? [{ type: 'paragraph' }] : content.value })
}
// A task list trailing an item's blocks stands beside it, as ADF nests one.
function bulletNode(items: readonly Block[][], reading: Reading, path: ConvertErrorPath, depth: number): Result<AdfNode> {
const led = []
for (const [first, ...others] of items) {
@@ -212,10 +211,7 @@ function bulletNode(items: readonly Block[][], reading: Reading, path: ConvertEr
const marked: TaskParagraph[] = body === '' ? [] : [{ kind: 'taskParagraph', position, text: body }]
const read = readBlocks([...marked, ...others], reading, [...path, 'content', index], depth + 1)
if (!read.ok) return read
let beside = read.value.length
while (read.value[beside - 1]?.type === 'taskList') beside -= 1
tasks.push({ attrs: { state: marker.state }, content: read.value.slice(0, beside), type: 'blockTaskItem' })
for (const nested of read.value.slice(beside)) tasks.push(nested)
tasks.push({ attrs: { state: marker.state }, content: read.value, type: 'blockTaskItem' })
}
return success({ content: tasks, type: 'taskList' })
}
@@ -167,6 +167,11 @@ test('stands a block a task item cannot hold, and what follows it in the item, a
bare('codeBlock', text('x')),
])
assert.deepEqual(read('- [x] A\n - plain\n- [ ] B\n'), [bare('taskList', task('DONE', text('A'))), bare('bulletList', bare('listItem', said('plain'))), bare('taskList', task('TODO', text('B')))])
assert.deepEqual(read('- [ ] A\n - [ ] Child\n\n # h\n- [ ] B\n'), [
bare('taskList', task('TODO', text('A')), bare('taskList', task('TODO', text('Child')))),
node('heading', { level: 1 }, text('h')),
bare('taskList', task('TODO', text('B'))),
])
assert.deepEqual(read('- [ ] A\n\n # h\n - [ ] Child\n- [ ] B\n'), [
bare('taskList', task('TODO', text('A'))),
node('heading', { level: 1 }, text('h')),