mirror of
https://github.com/larvit/adf-codec.git
synced 2026-11-19 06:35:44 +01:00
Count a textless holder as a stripping run end, and test the nested count offset
This commit is contained in:
@@ -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])
|
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][] = [
|
const alternatingLines: readonly [string, AdfNode, AdfNode][] = [
|
||||||
['a code space beside an emphasized space', marked(' ', { type: 'code' }), marked(' ', { type: 'em' })],
|
['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' })],
|
['code x beside an emphasized space', marked('x', { type: 'code' }), marked(' ', { type: 'em' })],
|
||||||
|
|||||||
@@ -261,7 +261,7 @@ export function trimmingRuns(leaves: readonly AdfNode[], grouping: RunGrouping):
|
|||||||
function countTrimmingRuns(nodes: readonly RunNode[], firstIndex: number, grouping: RunGrouping, shared: number[]): void {
|
function countTrimmingRuns(nodes: readonly RunNode[], firstIndex: number, grouping: RunGrouping, shared: number[]): void {
|
||||||
for (const run of inlineRuns(nodes, firstIndex, grouping)) {
|
for (const run of inlineRuns(nodes, firstIndex, grouping)) {
|
||||||
if (run.kind === 'plain') continue
|
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 holders = run.nodes.flatMap((runNode, offset) => (holds(runNode) ? [offset] : []))
|
||||||
const first = holders[0]
|
const first = holders[0]
|
||||||
const last = holders.at(-1)
|
const last = holders.at(-1)
|
||||||
|
|||||||
Reference in New Issue
Block a user