mirror of
https://github.com/larvit/adf-codec.git
synced 2026-11-12 19:58:28 +01:00
Answer stability round 1: 0 🔴, 1 🟡; pin the nesting limit of task lists
This commit is contained in:
@@ -219,7 +219,7 @@ 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 unplaced rather than asserting; task-list.test.ts pins that the split keeps it.
|
||||
// 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.
|
||||
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 }
|
||||
|
||||
@@ -205,6 +205,19 @@ 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', () => {
|
||||
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))
|
||||
assert.deepEqual(refused.ok ? undefined : [refused.error.code, refused.error.path], [
|
||||
'unsupported-nesting-depth',
|
||||
['content', 0, ...Array.from({ length: largestNesting }, () => ['content', 1]).flat(), 'content', 0],
|
||||
])
|
||||
assert.ok(portableMarkdownToAdf(`${'> '.repeat(largestNesting - 1)}- [ ] a\n`).ok)
|
||||
const quoted = portableMarkdownToAdf(`${'> '.repeat(largestNesting)}- [ ] a\n`)
|
||||
assert.equal(quoted.ok ? undefined : quoted.error.code, 'unsupported-nesting-depth')
|
||||
})
|
||||
|
||||
test('reads a task list beside a list of another bullet character as two lists', () => {
|
||||
const tasks = (state: string, value: string): AdfNode => bare('taskList', node('taskItem', { state }, text(value)))
|
||||
assert.deepEqual(read('- [x] a\n* b\n'), [tasks('DONE', 'a'), bare('bulletList', bare('listItem', bare('paragraph', text('b'))))])
|
||||
|
||||
Reference in New Issue
Block a user