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

Answer stability round 2: 1 🔴, 0 🟡 (0 misread); a line gives up every highlight run whose own delimiters cannot flank in one pass, as shipped, so a line of them re-emits once, and the reader records no highlight pairs

This commit is contained in:
2026-10-28 18:10:03 +01:00
committed by Lillem4n
parent 5107c9506b
commit 2f9a1b3540
5 changed files with 44 additions and 30 deletions
+9 -3
View File
@@ -230,7 +230,7 @@ function spellableLine(leaves: AdfNode[], container: LineContainer, path: Conver
}
function withoutFallback(leaves: readonly AdfNode[], fallback: PortableLineFallback): AdfNode[] | undefined {
if (fallback.kind === 'unspellable-run') return withoutMark(leaves, fallback.run)
if (fallback.kind === 'unspellable-run') return withoutMarks(leaves, fallback.runs)
const mark = nodeMarks(leaves[0] ?? {})[0]
if (mark === undefined || mark.type !== 'link') return undefined
let last = 0
@@ -240,6 +240,12 @@ function withoutFallback(leaves: readonly AdfNode[], fallback: PortableLineFallb
return spans ? leaves.map((leaf, index) => (index > last ? leaf : withMarks(leaf, nodeMarks(leaf).filter((held) => held.type !== 'code')))) : undefined
}
function withoutMark(leaves: readonly AdfNode[], run: MarkRun): AdfNode[] {
return leaves.map((leaf, index) => (index < run.first || index > run.last ? leaf : withMarks(leaf, nodeMarks(leaf).filter((_, held) => held !== run.depth))))
// The runs cover disjoint leaves, so one pass drops them all.
function withoutMarks(leaves: readonly AdfNode[], runs: readonly MarkRun[]): AdfNode[] {
const depths = new Map<number, number>()
for (const run of runs) for (let index = run.first; index <= run.last; index += 1) depths.set(index, run.depth)
return leaves.map((leaf, index) => {
const depth = depths.get(index)
return depth === undefined ? leaf : withMarks(leaf, nodeMarks(leaf).filter((_, held) => held !== depth))
})
}