diff --git a/src/markdown/portable/inline-reduction.test.ts b/src/markdown/portable/inline-reduction.test.ts index 8d7fd36..4107921 100644 --- a/src/markdown/portable/inline-reduction.test.ts +++ b/src/markdown/portable/inline-reduction.test.ts @@ -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' })], diff --git a/src/markdown/portable/inline-reduction.ts b/src/markdown/portable/inline-reduction.ts index 825b873..71433dd 100644 --- a/src/markdown/portable/inline-reduction.ts +++ b/src/markdown/portable/inline-reduction.ts @@ -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)