mirror of
https://github.com/larvit/adf-codec.git
synced 2026-11-21 07:32:58 +01:00
Answer architecture round 1: 1 🔴, 3 🟡; name the other-target link and no-alt case, pin both, file items 117 and 118
This commit is contained in:
@@ -80,15 +80,18 @@ function idMention(id: unknown): string | undefined {
|
||||
return typeof id === 'string' && id !== '' ? `@${id}` : undefined
|
||||
}
|
||||
|
||||
// An image standing inline is a link to it: CommonMark's inline image reads back as no node.
|
||||
// An image standing inline is a link to it: CommonMark's inline image reads back as no node, and one inside a link as the link's text.
|
||||
function mediaLeaves(attrs: Readonly<AdfAttributes>, marks: readonly AdfMark[], container: LineContainer): AdfNode[] {
|
||||
const alt = nonEmpty(attrs['alt'])
|
||||
const url = nonEmpty(attrs['url'])
|
||||
if (attrs['type'] !== 'external' || url === undefined) return textLeaves(alt, marks, container, 'image')
|
||||
const href = nodeAttrs(marks.find((mark) => mark.type === 'link') ?? {})['href']
|
||||
if (href === url) return textLeaves(alt ?? url, marks, container)
|
||||
const link = marks.find((mark) => mark.type === 'link')
|
||||
const href = link === undefined ? undefined : nodeAttrs(link)['href']
|
||||
if (typeof href !== 'string') return linkedLeaves(alt ?? url, url, marks, container)
|
||||
return [...textLeaves(alt ?? url, marks, container), textLeaf(' (', []), ...linkedLeaves('image', url, marks, container), textLeaf(')', [])]
|
||||
if (href === url) return textLeaves(alt ?? url, marks, container)
|
||||
const linkedAlt = textLeaves(alt ?? nonEmpty(href) ?? url, marks, container)
|
||||
const image = linkedLeaves('image', url, marks, container)
|
||||
return [...linkedAlt, textLeaf(' (', []), ...image, textLeaf(')', [])]
|
||||
}
|
||||
|
||||
function noteLeaves(name: string): AdfNode[] {
|
||||
|
||||
Reference in New Issue
Block a user