diff --git a/src/markdown/emit/adf-to-markdown.test.ts b/src/markdown/emit/adf-to-markdown.test.ts index 11f5013..22bead4 100644 --- a/src/markdown/emit/adf-to-markdown.test.ts +++ b/src/markdown/emit/adf-to-markdown.test.ts @@ -722,6 +722,9 @@ test('spells a mark run across the hard break between two nodes holding the mark assert.equal(readsBack(document(paragraph(marked('a', link), hardBreak, marked('b', link)))), '[a\\\nb](/u)\n') assert.equal(readsBack(document(paragraph(marked('a', em, link), hardBreak, marked('b', em)))), '_[a](/u)\\\nb_\n') assert.equal(readsBack(document(paragraph(marked('a', em), hardBreak, hardBreak, marked('b', em)))), '_a\\\n\\\nb_\n') + const directive: AdfMark = { attrs: { href: '/u', id: 'x' }, type: 'link' } + assert.equal(readsBack(document(paragraph(marked('a', directive), hardBreak, marked('b', directive)))), '!adf:link[a]{href="/u" id=x}\\\n!adf:link[b]{href="/u" id=x}\n') + readsBack(document(paragraph(marked(']: /x', link, { type: 'code' }), hardBreak, marked('b', link)))) assert.equal(readsBack(document(paragraph({ text: 'x', type: 'text' }, marked('.', em), hardBreak, marked('b', em)))), 'x!adf:carry{json="{\\"marks\\":[{\\"type\\":\\"em\\"}],\\"text\\":\\".\\",\\"type\\":\\"text\\"}"}\\\n_b_\n') }) diff --git a/src/markdown/emit/inline-line.ts b/src/markdown/emit/inline-line.ts index 9fbd171..f6f4b46 100644 --- a/src/markdown/emit/inline-line.ts +++ b/src/markdown/emit/inline-line.ts @@ -327,6 +327,8 @@ function emitMarkedRun(nodes: readonly AdfNode[], mark: AdfMark, depth: number, const inner = emitRun(nodes, depth + 1, index, { ...context, bracketed: true }) if (!inner.ok) return inner if (inner.value.carry !== undefined) return inner + // A link `tryLink` gave back holds the hard breaks `joinsRun` joined; the carry's fallback parts them. + if (inner.value.segments.some((segment) => segment.text.includes('\n'))) return success({ carry: range }) return success({ segments: [syntax(spellInlineDirectiveOpener(mark.type)), ...inner.value.segments, syntax(`]${attributes}`)] }) } diff --git a/todo.md b/todo.md index ff49da4..ddffe07 100644 --- a/todo.md +++ b/todo.md @@ -325,8 +325,8 @@ quadratic in a run of blanks inside one leaf: a paragraph of `a`, 80 000 spaces, `adfToLosslessMarkdown` spends 23 s on one paragraph of 2000 × `un` plus `**-r**`: each run its flanking cannot spell re-emits the whole line before riding the carry, quadratic in the runs, and the portable reduction's `spellableLine` drops one mark per re-emit the same way. An inline node -whose attributes no spelling writes re-emits the line the same way before riding the carry. Make all -three linear. +whose attributes no spelling writes re-emits the line the same way before riding the carry, and so +does an emphasis or link run that parts at the hard breaks it spans. Make all four linear. ### 56. Give each piece of `blocks.ts`'s block-walk state and `inline-content.ts`'s `Scan` one owner that returns what it changes.