16 - no link wraps a link #104

Merged
lilleman merged 8 commits from link-wrapping-a-link into main 2026-09-19 02:34:21 +02:00
2 changed files with 2 additions and 3 deletions
Showing only changes of commit a2928a8789 - Show all commits
+2 -2
View File
@@ -39,7 +39,7 @@ type Run = { canClose: boolean; canOpen: boolean; character: string; index: numb
// `container` is `undefined` inside a directive's content slot, the emitter's `bracketed`. // `container` is `undefined` inside a directive's content slot, the emitter's `bracketed`.
type Scan = { type Scan = {
container: LineContainer | undefined container: LineContainer | undefined
// Pieces below this have been walked for openers to deactivate: one left active reaches closeLink, whose image and carry guards refuse what literal brackets hold fine. // Pieces below this have been walked for openers to deactivate: one left active reaches closeLink, whose image and carry guards refuse a span going literal anyway.
deactivatedBefore: number deactivatedBefore: number
definitions: LinkDefinitions definitions: LinkDefinitions
openingSpellableLink: boolean openingSpellableLink: boolean
@@ -369,7 +369,7 @@ function closeLink(scan: Scan, at: number, inner: readonly Piece[], definition:
// CommonMark: no link nests inside another, though an image's description holds one. // CommonMark: no link nests inside another, though an image's description holds one.
function deactivateOpeners(scan: Scan, before: number): void { function deactivateOpeners(scan: Scan, before: number): void {
for (let index = Math.min(scan.deactivatedBefore, before); index < before; index += 1) { for (let index = scan.deactivatedBefore; index < before; index += 1) {
const piece = scan.pieces[index] const piece = scan.pieces[index]
if (piece?.kind === 'open' && !piece.image) piece.active = false if (piece?.kind === 'open' && !piece.image) piece.active = false
} }
@@ -841,7 +841,6 @@ test('leaves the brackets of a link whose text already holds one the text they a
]) ])
}) })
// Literal brackets hold what no mark may, so the openers they doom give way before closeLink refuses a carry or an image inside them.
test('keeps the carry and the image the brackets a nested link leaves literal hold', () => { test('keeps the carry and the image the brackets a nested link leaves literal hold', () => {
assert.deepEqual(content(markdownToAdf('[[<http://x/>](/c)!adf:carry{json="{\\"type\\":\\"blockCard\\"}"}](/w)\n')), [ assert.deepEqual(content(markdownToAdf('[[<http://x/>](/c)!adf:carry{json="{\\"type\\":\\"blockCard\\"}"}](/w)\n')), [
{ content: [text('[['), marked('http://x/', link('http://x/')), text('](/c)'), { type: 'blockCard' }, text('](/w)')], type: 'paragraph' }, { content: [text('[['), marked('http://x/', link('http://x/')), text('](/c)'), { type: 'blockCard' }, text('](/w)')], type: 'paragraph' },