3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-21 15:42:58 +01:00

Place a refused task-list block by the one split of the list

This commit is contained in:
2026-10-22 13:15:25 +02:00
committed by Lillem4n
parent 110707f907
commit f3b0576023
7 changed files with 90 additions and 58 deletions
+1 -1
View File
@@ -716,7 +716,7 @@ held; the scores at 6182ba6 were Junior 5.5, Mid 5.5, Senior 6 and Architect 5.5
rounds under a fall the seats laid on item 93's `splitPath` and `splitPlace`, which place a refused rounds under a fall the seats laid on item 93's `splitPath` and `splitPlace`, which place a refused
block's path by replaying `splitTaskList` on stand-in nodes; both seats read the chunk's own image block's path by replaying `splitTaskList` on stand-in nodes; both seats read the chunk's own image
builder as a gain. The scores at be23835 were Junior 6.5, Mid 6, Senior 6 and Architect 6, mean builder as a gain. The scores at be23835 were Junior 6.5, Mid 6, Senior 6 and Architect 6, mean
6.13. `todo.md` item 102 is to place that path without the replay. Item 106, 2026-10-13, shipped 6.13. Item 102, 2026-10-22, placed that path in the blocks the one split built. Item 106, 2026-10-13, shipped
after three rounds under a worse ruling, the maintainer's call: both paired seats read the overall after three rounds under a worse ruling, the maintainer's call: both paired seats read the overall
as the same, but Locality fell to a mean of 5.13, laid on the spelling memo the chunk splits between as the same, but Locality fell to a mean of 5.13, laid on the spelling memo the chunk splits between
the CommonMark ask, which fills it, and the walk, which drops each entry as it reads it. The overall the CommonMark ask, which fills it, and the walk, which drops each entry as it reads it. The overall
+4
View File
@@ -454,3 +454,7 @@ Read most (opens and searches):
141844 new input tokens before the first commit. 141844 new input tokens before the first commit.
## Reading cost reset, 2026-10-22T10:57:54Z ## Reading cost reset, 2026-10-22T10:57:54Z
## Reading cost, chunk d728d0158069, finished 2026-10-22T11:05:26Z
60874 new input tokens before the first commit.
+41 -35
View File
@@ -8,8 +8,8 @@ import type { LinkDefinitions } from './inline-content.ts'
import { carryFenceType, readCarriedBlock } from '../opaque-carry.ts' import { carryFenceType, readCarriedBlock } from '../opaque-carry.ts'
import { commonMarkSpelling, type SpellingMemo } from '../emit/spelling-questions.ts' import { commonMarkSpelling, type SpellingMemo } from '../emit/spelling-questions.ts'
import { documentAttribute, documentName, documentSpelling } from '../directive/block.ts' import { documentAttribute, documentName, documentSpelling } from '../directive/block.ts'
import { emptyKeys, nodeAttrs, nodeContent } from '../../adf/document.ts' import { emptyKeys, nodeAttrs } from '../../adf/document.ts'
import { failure, faulted, positioned, success, type ConvertErrorPath, type ParseError, type Result, type SourcePosition } from '../../result.ts' import { failure, faulted, positioned, success, type ConvertError, type ConvertErrorPath, type ParseError, type Result, type SourcePosition } from '../../result.ts'
import { flavourClaims } from '../flavour.ts' import { flavourClaims } from '../flavour.ts'
import { languageSlot } from '../code-language.ts' import { languageSlot } from '../code-language.ts'
import { largestNesting } from '../../nesting.ts' import { largestNesting } from '../../nesting.ts'
@@ -20,7 +20,7 @@ import { parseInlineContent } from './inline-content.ts'
import { readBlockDirectiveNode } from '../directive/node-reading.ts' import { readBlockDirectiveNode } from '../directive/node-reading.ts'
import { spellStringAttribute, unsupportedNodeShape } from '../directive/syntax.ts' import { spellStringAttribute, unsupportedNodeShape } from '../directive/syntax.ts'
import { spellsEmpty } from '../directive/empty-keys.ts' import { spellsEmpty } from '../directive/empty-keys.ts'
import { splitPlace, splitTaskList } from '../portable/task-list.ts' import { pathTo, splitTaskList } from '../portable/task-list.ts'
import { withinEngineLimits } from '../length-bound.ts' import { withinEngineLimits } from '../length-bound.ts'
type Paragraph = Extract<Block, { kind: 'paragraph' }> type Paragraph = Extract<Block, { kind: 'paragraph' }>
@@ -210,52 +210,58 @@ function taskItems(items: readonly Block[][]) {
} }
function bulletBlocks(items: readonly Block[][], reading: Reading, path: ConvertErrorPath, depth: number): Result<AdfNode[]> { function bulletBlocks(items: readonly Block[][], reading: Reading, path: ConvertErrorPath, depth: number): Result<AdfNode[]> {
const led = taskItems(items) const tasks = taskBlocks(items, reading, path, depth)
if (led === undefined) { if (tasks === undefined) {
const list = listNode({ type: 'bulletList' }, items, reading, path, depth) const list = listNode({ type: 'bulletList' }, items, reading, path, depth)
return list.ok ? success([list.value]) : list return list.ok ? success([list.value]) : list
} }
if (!tasks.ok) return tasks
const { nodes: blocks, refusal } = tasks.value
if (refusal === undefined) return success(blocks)
const listIndex = path.at(-1)
const place = pathTo(blocks, refusal.marker)
if (place === undefined || typeof listIndex !== 'number') 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` 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.
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.
type TaskNodes = { nodes: AdfNode[]; refusal: Refusal | undefined }
function taskBlocks(items: readonly Block[][], reading: Reading, path: ConvertErrorPath, depth: number): Result<TaskNodes> | undefined {
const led = taskItems(items)
if (led === undefined) return undefined
if (depth + 1 > largestNesting) return tooDeep([...path, 'content', 0]) if (depth + 1 > largestNesting) return tooDeep([...path, 'content', 0])
const tasks: AdfNode[] = [] const tasks: AdfNode[] = []
let refusal: Refusal | undefined
for (const [index, { marker, others, position, text }] of led.entries()) { for (const [index, { marker, others, position, text }] of led.entries()) {
const body = text.replace(/^(?:[ \t\n]|\\\n)+/, '') const body = text.replace(/^(?:[ \t\n]|\\\n)+/, '')
const marked: TaskParagraph[] = body === '' ? [] : [{ kind: 'taskParagraph', position, text: body }] const marked: TaskParagraph[] = body === '' ? [] : [{ kind: 'taskParagraph', position, text: body }]
const blocks = [...marked, ...others]
const task: AdfNode & { content: AdfNode[] } = { attrs: { state: marker.state }, content: [], type: 'blockTaskItem' } const task: AdfNode & { content: AdfNode[] } = { attrs: { state: marker.state }, content: [], type: 'blockTaskItem' }
for (const [at, block] of blocks.entries()) { for (const block of [...marked, ...others]) {
const read = readBlocks([block], reading, [...path, 'content', index], depth + 1) const read = readTaskBlock(block, reading, [...path, 'content', index], depth + 1)
if (!read.ok) return { error: { ...read.error, path: splitPath(read.error.path, { block, next: blocks[at + 1], path, reading, task, tasks }) }, ok: false } for (const node of read.nodes) task.content.push(node)
for (const node of read.value) task.content.push(node) refusal ??= read.refusal
} }
tasks.push(task) tasks.push(task)
if (refusal !== undefined) break
} }
return success(splitTaskList({ content: tasks, type: 'taskList' })) return success({ nodes: splitTaskList({ content: tasks, type: 'taskList' }), refusal })
} }
type Refusal = { block: ReadBlock; next: ReadBlock | undefined; path: ConvertErrorPath; reading: Reading; task: AdfNode; tasks: readonly AdfNode[] } // 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.
function readTaskBlock(block: ReadBlock, reading: Reading, path: ConvertErrorPath, depth: number): TaskNodes {
// splitTaskList moves a task's children, so the path names where the refused block's node will stand: the split runs with a stand-in of that node's type. const nodePath = [...path, 'content', 0]
function splitPath(refused: ConvertErrorPath, { block, next, path, reading, task, tasks }: Refusal): ConvertErrorPath { const nested = block.kind === 'bulletList' && depth <= largestNesting ? taskBlocks(block.items, reading, nodePath, depth) : undefined
const [, offset, ...within] = refused.slice(path.length + 2) if (nested?.ok) return nested.value
const listIndex = path.at(-1) const read = positioned(nested ?? readBlocks([block], reading, path, depth), block.position)
if (typeof offset !== 'number' || typeof listIndex !== 'number') return refused if (read.ok) return { nodes: read.value, refusal: undefined }
// A nested task list reads as a task list, then the blocks its own split moved out; a bulletList stands in for each of those, since the split moves it out too. const marker: AdfNode = { text: '', type: 'text' }
const before = Array.from({ length: offset }, (_, at): AdfNode => ({ type: at === 0 ? 'taskList' : 'bulletList' })) const type = block.kind === 'taskParagraph' ? 'paragraph' : block.kind === 'bulletList' && taskItems(block.items) !== undefined ? 'taskList' : block.kind
const node: AdfNode & { content: [AdfNode] } = { content: [{ text: '', type: 'text' }], type: offset === 0 ? childType(block, reading) : 'bulletList' } return { nodes: [{ content: [marker], type }], refusal: { error: read.error, marker, within: read.error.path.slice(nodePath.length) } }
const after = next === undefined ? [] : [{ type: childType(next, reading) }]
const list = { content: [...tasks, { ...task, content: [...nodeContent(task), ...before, node, ...after] }], type: 'taskList' }
const place = splitPlace(list, node)
if (place === undefined) return refused
const [blockIndex, ...steps] = place
return [...path.slice(0, -1), listIndex + blockIndex, ...steps, ...within]
}
// The split tells only paragraphs and task lists from other blocks, so any other block's kind serves as its type; a paragraph may read as another node.
function childType(block: ReadBlock, reading: Reading): string {
if (block.kind === 'bulletList') return taskItems(block.items) === undefined ? 'bulletList' : 'taskList'
if (block.kind !== 'paragraph') return block.kind === 'taskParagraph' ? 'paragraph' : block.kind
const read = paragraphNode(block.text, reading, [])
return read.ok ? read.value.type : 'paragraph'
} }
function directiveNode(block: DirectiveBlock, reading: Reading, path: ConvertErrorPath, depth: number): Result<AdfNode> { function directiveNode(block: DirectiveBlock, reading: Reading, path: ConvertErrorPath, depth: number): Result<AdfNode> {
@@ -197,6 +197,12 @@ test('names where a refused block stands after the task list splits', () => {
assert.equal(refused('- [ ] A\n\n # h\n - [ ] C <b>x</b>\n'), '/content/2/content/0') assert.equal(refused('- [ ] A\n\n # h\n - [ ] C <b>x</b>\n'), '/content/2/content/0')
assert.equal(refused('- [ ] A\n - [ ] C\n\n # h\n\n <div>x</div>\n'), '/content/2') assert.equal(refused('- [ ] A\n - [ ] C\n\n # h\n\n <div>x</div>\n'), '/content/2')
assert.equal(refused('> q\n>\n> - [ ] A\n>\n> # h\n>\n> <div>x</div>\n'), '/content/0/content/3') assert.equal(refused('> q\n>\n> - [ ] A\n>\n> # h\n>\n> <div>x</div>\n'), '/content/0/content/3')
assert.equal(refused('- [ ] a <b>x</b>\n\n # h\n'), '/content/0/content/0')
assert.equal(refused('- [ ] A\n - [ ] B\n\n # h\n - [ ] C <b>x</b>\n'), '/content/2/content/0')
assert.equal(refused('- [ ] A\n - [ ] B\n\n # h\n - [ ] C\n\n <div>x</div>\n'), '/content/3')
assert.equal(refused('- [ ] A\n - [ ] B\n - [ ] C <b>x</b>\n'), '/content/0/content/1/content/1/content/0')
assert.equal(refused('- [ ] A\n - [ ] B <b>x</b>\n - [ ] C <i>y</i>\n'), '/content/0/content/1/content/0')
assert.equal(refused('- [ ] a\n\n <div>x</div>\n\n tail <b>y</b>\n'), '/content/1')
}) })
test('reads a task list beside a list of another bullet character as two lists', () => { test('reads a task list beside a list of another bullet character as two lists', () => {
+20
View File
@@ -0,0 +1,20 @@
import assert from 'node:assert/strict'
import test from 'node:test'
import type { AdfNode } from '../../adf/document.ts'
import { pathTo, splitTaskList } from './task-list.ts'
test('names the steps from a block to a node deep in it, and none for a node it does not hold', () => {
const target: AdfNode = { text: 'x', type: 'text' }
const blocks: AdfNode[] = [{ type: 'rule' }, { content: [{ content: [{ type: 'paragraph' }, { content: [target], type: 'paragraph' }], type: 'blockquote' }], type: 'panel' }]
assert.deepEqual(pathTo(blocks, target), [1, 'content', 0, 'content', 1, 'content', 0])
assert.deepEqual(pathTo(blocks, blocks[0] ?? target), [0])
assert.equal(pathTo(blocks, { text: 'x', type: 'text' }), undefined)
})
test('keeps the inline nodes of a lone paragraph in the taskItem it becomes, so pathTo still finds them', () => {
const inline: AdfNode = { text: 'x', type: 'text' }
const item: AdfNode = { attrs: { state: 'TODO' }, content: [{ content: [inline], type: 'paragraph' }], type: 'blockTaskItem' }
const blocks = splitTaskList({ content: [item], type: 'taskList' })
assert.deepEqual(pathTo(blocks, inline), [0, 'content', 0, 'content', 0])
})
+17 -13
View File
@@ -19,19 +19,23 @@ export function splitTaskList(list: AdfNode): AdfNode[] {
return blocks return blocks
} }
// Where `node`, a child of one of the list's tasks, stands among the blocks splitTaskList returns; a task's lone paragraph becomes a taskItem, found by the paragraph's first inline node. // 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.
export function splitPlace(list: AdfNode, node: AdfNode & { content: [AdfNode] }): [number, ...ConvertErrorPath] | undefined { export function pathTo(blocks: readonly AdfNode[], target: AdfNode): [number, ...ConvertErrorPath] | undefined {
const [inline] = node.content const pending: Visit[] = blocks.map((node, step) => ({ node, parent: undefined, step }))
const places = splitTaskList(list).flatMap((block, index): [number, ...ConvertErrorPath][] => { for (let visit = pending.pop(); visit !== undefined; visit = pending.pop()) {
if (block === node) return [[index]] if (visit.node === target) return stepsTo(visit)
if (block.type !== 'taskList') return [] for (const [step, node] of nodeContent(visit.node).entries()) pending.push({ node, parent: visit, step })
return nodeContent(block).flatMap((item, child): [number, ...ConvertErrorPath][] => { }
if (item === node || nodeContent(item)[0] === inline) return [[index, 'content', child]] return undefined
const at = nodeContent(item).indexOf(node) }
return at === -1 ? [] : [[index, 'content', child, 'content', at]]
}) type Visit = { node: AdfNode; parent: Visit | undefined; step: number }
})
return places[0] function stepsTo(visit: Visit): [number, ...ConvertErrorPath] {
const steps: (number | string)[] = []
let at = visit
for (; at.parent !== undefined; at = at.parent) steps.push(at.step, 'content')
return [at.step, ...steps.reverse()]
} }
// An item is a task and the children up to the next one. // An item is a task and the children up to the next one.
+1 -9
View File
@@ -12,7 +12,6 @@
| ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves | Score | | ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves | Score |
|---|---|---|---|---|---|---|---|---|---|---|---| |---|---|---|---|---|---|---|---|---|---|---|---|
| 102 | 0.3.0 | | decision | **Place a block a portable task list refuses at its path in the returned document without replaying `splitTaskList` on stand-in nodes.** | 2 | 1 | 2 | 3 | 4 | code health by 4 | 17.4 |
| 62 | 0.3.0 | | decision | **Move the portable flavour's reading out of `parse/` and its writing out of `emit/` into `markdown/portable/`, so `emit/` no longer imports `portable/`.** | 3 | 1 | 2 | 4 | 5 | code health by 5 | 13.1 | | 62 | 0.3.0 | | decision | **Move the portable flavour's reading out of `parse/` and its writing out of `emit/` into `markdown/portable/`, so `emit/` no longer imports `portable/`.** | 3 | 1 | 2 | 4 | 5 | code health by 5 | 13.1 |
| 123 | 0.3.0 | | defect | **Spell a link title holding a backslash, an entity reference or, in a table cell, a pipe, instead of dropping it.** | 3 | 1 | 2 | 4 | 3 | 7 by 2 | 13.1 | | 123 | 0.3.0 | | defect | **Spell a link title holding a backslash, an entity reference or, in a table cell, a pipe, instead of dropping it.** | 3 | 1 | 2 | 4 | 3 | 7 by 2 | 13.1 |
| 122 | 0.3.0 | | defect | **Keep an image's URL and title when a link's text holds the image, instead of dropping them.** | 3 | 1 | 2 | 4 | 5 | 7 by 4 | 10.5 | | 122 | 0.3.0 | | defect | **Keep an image's URL and title when a link's text holds the image, instead of dropping them.** | 3 | 1 | 2 | 4 | 5 | 7 by 4 | 10.5 |
@@ -22,7 +21,7 @@
| 109 | 0.3.0 | | defect | **Spell nested lists and quotes in time linear in the markdown.** | 3 | 1 | 2 | 4 | 5 | 9 by 3 | 7.8 | | 109 | 0.3.0 | | defect | **Spell nested lists and quotes in time linear in the markdown.** | 3 | 1 | 2 | 4 | 5 | 9 by 3 | 7.8 |
| 115 | 0.3.0 | | defect | **Build text holding no `border` mark in `losslessMarkdownToAdf`, and have `adfToLosslessMarkdown` carry text holding one.** | 2 | 1 | 2 | 3 | 3 | 4 by 3 | 4.6 | | 115 | 0.3.0 | | defect | **Build text holding no `border` mark in `losslessMarkdownToAdf`, and have `adfToLosslessMarkdown` carry text holding one.** | 2 | 1 | 2 | 3 | 3 | 4 by 3 | 4.6 |
| 91 | 0.3.0 | 95 | | **Spell an emphasis once across the code spans, an emphasis or link once across the hard breaks, dates, emoji, inline cards, mentions and statuses between two nodes it marks, and an emphasis across inline media, in both writers.** | 3 | 2 | 2 | 5 | 5 | 6 by 6 | 3.6 | | 91 | 0.3.0 | 95 | | **Spell an emphasis once across the code spans, an emphasis or link once across the hard breaks, dates, emoji, inline cards, mentions and statuses between two nodes it marks, and an emphasis across inline media, in both writers.** | 3 | 2 | 2 | 5 | 5 | 6 by 6 | 3.6 |
| 73 | 0.3.0 | 33, 62, 91, 95, 102, 109, 115, 122, 123, 125 | | **Announce the package where someone needing an ADF converter already reads: JRACLOUD-77436, the Atlassian developer community and Stack Overflow's ADF-to-markdown questions.** | 1 | 2 | 2 | 3 | 2 | 3 by 8 | 16.9 | | 73 | 0.3.0 | 33, 62, 91, 95, 109, 115, 122, 123, 125 | | **Announce the package where someone needing an ADF converter already reads: JRACLOUD-77436, the Atlassian developer community and Stack Overflow's ADF-to-markdown questions.** | 1 | 2 | 2 | 3 | 2 | 3 by 8 | 16.9 |
| 75 | 0.4.0 | | | **Make the generated-markdown property write block carries as `adf:` fences, canonical and hostile.** | 1 | 1 | 1 | 1 | 2 | code health by 2 | 17.4 | | 75 | 0.4.0 | | | **Make the generated-markdown property write block carries as `adf:` fences, canonical and hostile.** | 1 | 1 | 1 | 1 | 2 | code health by 2 | 17.4 |
| 45 | 0.4.0 | | defect | **Replace `isAdfDocument` with a reader returning `Result<AdfDocument>`.** | 2 | 1 | 3 | 4 | 3 | 1 by 2 | 13.1 | | 45 | 0.4.0 | | defect | **Replace `isAdfDocument` with a reader returning `Result<AdfDocument>`.** | 2 | 1 | 3 | 4 | 3 | 1 by 2 | 13.1 |
| 68 | 0.4.0 | | defect | **Carry a non-text inline node holding `content` or `text`, a block holding `text`, and a leaf block holding `content`.** | 2 | 1 | 2 | 3 | 3 | 1 by 2 | 13.1 | | 68 | 0.4.0 | | defect | **Carry a non-text inline node holding `content` or `text`, a block holding `text`, and a leaf block holding `content`.** | 2 | 1 | 2 | 3 | 3 | 1 by 2 | 13.1 |
@@ -57,13 +56,6 @@
## Details ## Details
### 102. Place a block a portable task list refuses at its path in the returned document without replaying `splitTaskList` on stand-in nodes.
`splitPath` (`src/markdown/parse/markdown-to-adf.ts`) builds stand-ins and `splitPlace`
(`src/markdown/portable/task-list.ts`) finds them again by object identity, right only while
`taskOfParagraphs` keeps the original child objects. Both paired-ruling seats on 2026-10-11 named it
the reason the project read worse.
### 62. Move the portable flavour's reading out of `parse/` and its writing out of `emit/` into `markdown/portable/`, so `emit/` no longer imports `portable/`. ### 62. Move the portable flavour's reading out of `parse/` and its writing out of `emit/` into `markdown/portable/`, so `emit/` no longer imports `portable/`.
Reading: the alert and task-marker reads in `parse/markdown-to-adf.ts` and the `mintTaskIds` call. Reading: the alert and task-marker reads in `parse/markdown-to-adf.ts` and the `mintTaskIds` call.