3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-20 07:05:44 +01:00

Answer architecture round 5: 0 🔴, 0 🟡 (0 misread); shownImage returns no textless state, item 143 and the card rule name their whole reach

This commit is contained in:
2026-10-26 12:58:17 +01:00
parent 93a912db81
commit 9b43cb4fe9
6 changed files with 23 additions and 19 deletions
+3 -3
View File
@@ -39,11 +39,11 @@ export function referenceName(node: AdfNode): string | undefined {
}
}
// What an image shows in place of itself, `href` the target of the link marking it, if any: `text`, else a note; `link`, its URL, which `text` links to where no link marks it; `after`, its URL, shown after a link going elsewhere.
export function shownImage(media: AdfNode, href: string | undefined): { after: string | undefined; link: string | undefined; text: string | undefined } {
// What an image shows in place of itself, `href` the target of the link marking it, if any: `text`; `link`, its URL, which `text` links to where no link marks it; `after`, its URL, shown after a link going elsewhere. `undefined` where it shows no text, so a note stands in its place.
export function shownImage(media: AdfNode, href: string | undefined): { after: string | undefined; link: string | undefined; text: string } | undefined {
const alt = visibleText(nodeAttrs(media)['alt'])
const url = shownUrl(media)
if (url === undefined) return { after: undefined, link: undefined, text: alt }
if (url === undefined) return alt === undefined ? undefined : { after: undefined, link: undefined, text: alt }
if (href === undefined) return { after: undefined, link: url, text: alt ?? url }
if (href === url) return { after: undefined, link: undefined, text: alt ?? url }
return { after: url, link: undefined, text: alt ?? visibleText(href) ?? url }