diff --git a/src/markdown/parse/inline-content.ts b/src/markdown/parse/inline-content.ts index 978b7d9..821943a 100644 --- a/src/markdown/parse/inline-content.ts +++ b/src/markdown/parse/inline-content.ts @@ -67,6 +67,9 @@ type Scan = { spans: NestedSpans } +// What a directive's content slot inherits from the content holding it. +type SharedScan = Pick + type SlotContent = { carry: boolean; nodes: Inline[] } const carriedInMark = 'no mark spelling wraps an opaque carry or an inline node spelling marks=empty: its marks are its own' @@ -79,7 +82,7 @@ const textBreak: TextBreak = { kind: 'textBreak' } // The outermost content: only here does a text break see both its neighbours. export function parseInlineContent(source: string, definitions: LinkDefinitions, path: ConvertErrorPath, container: LineContainer, flavour: Flavour): Result { - const scan: Scan = { container, deactivatedBefore: 0, definitions, highlights: flavour === 'plain', openingSpellableLink: false, ownMarks: new Set(), path, pending: '', pieces: [], source, spans: noSpans } + const scan = freshScan(source, { definitions, ownMarks: new Set(), path }, { container, highlights: flavour === 'plain', spans: noSpans }) const scanned = scanInline(scan) if (!scanned.ok) return scanned if (scanned.value.image !== undefined) return success({ image: scanned.value.image }) @@ -93,6 +96,10 @@ export function parseInlineContent(source: string, definitions: LinkDefinitions, return success({ carry: scanned.value.carry, nodes: nodes.value }) } +function freshScan(source: string, shared: SharedScan, own: Pick): Scan { + return { ...shared, ...own, deactivatedBefore: 0, openingSpellableLink: false, pending: '', pieces: [], source } +} + function scanInline(scan: Scan): Result { const { source } = scan let index = 0 @@ -274,7 +281,8 @@ function refuseLinkDirective(scan: Scan, mark: AdfMark, nodes: readonly Inline[] function slotContent(scan: Scan, span: DirectiveSpan): Result { if (span.content === undefined) return success(undefined) - const parsed = scanInline({ ...scan, container: undefined, deactivatedBefore: 0, highlights: false, openingSpellableLink: false, pending: '', pieces: [], source: span.content, spans: span.spans }) + const { definitions, ownMarks, path } = scan + const parsed = scanInline(freshScan(span.content, { definitions, ownMarks, path }, { container: undefined, highlights: false, spans: span.spans })) if (!parsed.ok) return parsed if (parsed.value.image !== undefined) return failure('unmappable-image', imageAlone, scan.path) return success(parsed.value)