3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-18 22:25:44 +01:00

Count a textless holder as a stripping run end, and test the nested count offset

This commit is contained in:
2026-11-15 14:24:53 +01:00
committed by Lillem4n
parent 08abdd117f
commit 7d1e2d96ba
2 changed files with 10 additions and 1 deletions
@@ -106,6 +106,15 @@ test('counts an emphasis run from its first to its last leaf holding more than s
assert.deepEqual(trimmingRuns(line, 'spanned'), [1, 1, 2, 2, 1, 1, 0])
})
test('counts a run nested in an emphasis run from the emphasis run\'s first leaf holding more than spaces and tabs', () => {
const line = [marked(' ', { type: 'em' }), marked('x', { type: 'code' }), marked('a', { type: 'em' }, { type: 'strong' }), marked('x', { type: 'code' }), marked('b', { type: 'em' }, { type: 'strong' })]
assert.deepEqual(trimmingRuns(line, 'spanned'), [0, 0, 2, 2, 0])
})
test('counts an emphasis run to a leaf holding it and no text, which the trim never changes', () => {
assert.deepEqual(trimmingRuns([marked('a', { type: 'em' }), marked('x', { type: 'code' }), { attrs: { id: 'a' }, marks: [{ type: 'em' }], type: 'mention' }], 'spanned'), [1, 1, 0])
})
const alternatingLines: readonly [string, AdfNode, AdfNode][] = [
['a code space beside an emphasized space', marked(' ', { type: 'code' }), marked(' ', { type: 'em' })],
['code x beside an emphasized space', marked('x', { type: 'code' }), marked(' ', { type: 'em' })],
+1 -1
View File
@@ -261,7 +261,7 @@ export function trimmingRuns(leaves: readonly AdfNode[], grouping: RunGrouping):
function countTrimmingRuns(nodes: readonly RunNode[], firstIndex: number, grouping: RunGrouping, shared: number[]): void {
for (const run of inlineRuns(nodes, firstIndex, grouping)) {
if (run.kind === 'plain') continue
const holds = edgeStrippingMarks.includes(run.mark.type) ? ({ node }: RunNode) => nodeMarks(node).some((mark) => identicalMark(mark, run.mark)) && /[^ \t]/.test(node.text ?? '') : () => true
const holds = edgeStrippingMarks.includes(run.mark.type) ? ({ node }: RunNode) => nodeMarks(node).some((mark) => identicalMark(mark, run.mark)) && (node.text === undefined || /[^ \t]/.test(node.text)) : () => true
const holders = run.nodes.flatMap((runNode, offset) => (holds(runNode) ? [offset] : []))
const first = holders[0]
const last = holders.at(-1)