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

Answer stability round 1: 0 🔴, 6 🟡 (0 misread); restore inlineRuns's early exit, one mark equality, refuse a pass taking no mark, pin the carried range and the opening link's run

This commit is contained in:
2026-11-03 21:54:29 +01:00
committed by Lillem4n
parent f912d81371
commit bcdf224e4c
7 changed files with 61 additions and 17 deletions
+10
View File
@@ -49,6 +49,16 @@ test('refuses a node whose carry nests too deep ahead of a later node in its lin
assert.deepEqual(path(refused), ['content', 0, 'content', 0])
})
test('refuses a carried run at the node whose carry nests too deep, among the run\'s own nodes', () => {
let deep: JsonValue = 'a'
for (let depth = 0; depth < largestNesting - 1; depth += 1) deep = { deep }
const carriedEm: AdfNode = { marks: [{ attrs: { deep }, type: 'em' }], text: 'x', type: 'text' }
const twiceStrong: AdfNode = { marks: [{ type: 'strong' }, { type: 'strong' }], text: 'y', type: 'text' }
const refused = adfToLosslessMarkdown(document(paragraph({ text: 'ok', type: 'text' }, carriedEm, twiceStrong)))
assert.equal(code(refused), 'unsupported-nesting-depth')
assert.deepEqual(path(refused), ['content', 0, 'content', 1])
})
test('refuses a value that is not an ADF document, naming the check it failed', () => {
assert.equal(markdown(adfToLosslessMarkdown({ type: 'doc', version: Number.NaN })), 'not-an-adf-document: an ADF document holds a version number: found NaN')
})
+7 -5
View File
@@ -234,13 +234,15 @@ function inlineRuns(nodes: readonly RunNode[], firstIndex: number, carried: Read
for (const [offset, runNode] of nodes.entries()) {
const index = firstIndex + offset
const { node, outer } = runNode
const previous = runs[runs.length - 1]
// A carried node spells its marks inside the carry.
const carriedNode = carries(node, carried, index)
const inside = carriedNode || previous?.kind !== 'marked' ? undefined : insideRun(runNode, previous.mark)
const mark = carriedNode ? undefined : nodeMarks(node)[outer]
const mark = carries(node, carried, index) ? undefined : nodeMarks(node)[outer]
if (mark === undefined) {
runs.push({ index, kind: 'plain', node })
continue
}
const previous = runs[runs.length - 1]
const inside = previous?.kind === 'marked' ? insideRun(runNode, previous.mark) : undefined
if (previous?.kind === 'marked' && inside !== undefined) previous.nodes.push(inside)
else if (mark === undefined) runs.push({ index, kind: 'plain', node })
else runs.push({ index, kind: 'marked', mark, nodes: [{ node, outer: outer + 1 }] })
}
return runs