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

Answer prose round 1: 0 🔴, 4 🟡; fold item 102 into the decision's sentence and tighten the comments

This commit is contained in:
2026-10-22 19:15:15 +02:00
committed by Lillem4n
parent 41ccdcb76e
commit 5278f68262
4 changed files with 8 additions and 8 deletions
+3 -3
View File
@@ -219,13 +219,13 @@ function bulletBlocks(items: readonly Block[][], reading: Reading, path: Convert
const { nodes: blocks, refusal } = tasks.value
if (refusal === undefined) return success(blocks)
const place = pathTo(blocks, refusal.marker)
// Failures are values, so a marker the split ever copied out of sight leaves the error at its pre-split path rather than asserting; task-list.test.ts pins that the split keeps it.
// task-list.test.ts pins that the split keeps the marker; were it lost, the error keeps its pre-split path, since nothing here throws.
if (place === undefined) return { error: refusal.error, ok: false }
const [blockIndex, ...steps] = place
return { error: { ...refusal.error, path: [...path.slice(0, -1), listIndex + blockIndex, ...steps.slice(0, -2), ...refusal.within] }, ok: false }
}
// A block a task list refused. A placeholder holding `marker` as its one child stands where the block's node would, so the split that builds the list places the refusal too, and `within` is the error's path below that node.
// A block a task list refused. Its placeholder holds `marker` as its one child and stands where the block's node would, so the one split that builds the list places it; `within` is the error's path below that node.
type Refusal = { error: ConvertError; marker: AdfNode; within: ConvertErrorPath }
// Nodes read from task blocks and the first refusal among them; a list is read up to the task holding its refusal.
@@ -252,7 +252,7 @@ function taskBlocks(items: readonly Block[][], reading: Reading, path: ConvertEr
return success({ nodes: splitTaskList({ content: tasks, type: 'taskList' }), refusal })
}
// The nodes a block of a task reads to. A refused one is a placeholder, typed as the split tells paragraphs and task lists from other blocks, so a paragraph that failed to read stays a paragraph.
// A refused block reads to a placeholder. The split tells only paragraphs and task lists from other blocks, so a paragraph that failed to read stays a paragraph.
function readTaskBlock(block: ReadBlock, reading: Reading, path: ConvertErrorPath, depth: number): TaskNodes {
const nodePath = [...path, 'content', 0]
const nested = block.kind === 'bulletList' ? taskBlocks(block.items, reading, nodePath, depth) : undefined
@@ -205,7 +205,7 @@ test('names where a refused block stands after the task list splits', () => {
assert.equal(refused('- [ ] a\n\n <div>x</div>\n\n tail <b>y</b>\n'), '/content/1')
})
test('holds task lists to the 500 levels the parser carries, refusing one level deeper where it stands', () => {
test('refuses a task list nested one level past the 500 the parser carries, at its deepest item', () => {
const nested = (levels: number): string => Array.from({ length: levels }, (_, level) => `${' '.repeat(level)}- [ ] a\n`).join('')
assert.ok(portableMarkdownToAdf(nested(largestNesting)).ok)
const refused = portableMarkdownToAdf(nested(largestNesting + 1))
+1 -1
View File
@@ -19,7 +19,7 @@ export function splitTaskList(list: AdfNode): AdfNode[] {
return blocks
}
// Where `target` stands among `blocks`: its block's index, then the steps down to it. Every node the split moves keeps its identity, but a lone paragraph, which becomes a taskItem holding its inline nodes.
// Where `target` stands among `blocks`: its block's index, then the steps down to it. The split rebuilds lists and items but never an inline node, so an inline marker stays findable.
export function pathTo(blocks: readonly AdfNode[], target: AdfNode): [number, ...ConvertErrorPath] | undefined {
const pending: Visit[] = blocks.map((node, step) => ({ node, parent: undefined, step }))
for (let visit = pending.pop(); visit !== undefined; visit = pending.pop()) {