mirror of
https://github.com/larvit/adf-codec.git
synced 2026-11-20 15:15: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:
@@ -48,9 +48,9 @@ test('shows an image a link to another target marks by its alt, else the target,
|
||||
assert.deepEqual(shownImage({ attrs: { type: 'external', url: moon }, type: 'media' }, ' '), { after: moon, link: undefined, text: moon })
|
||||
})
|
||||
|
||||
test('shows an image with no URL by its alt, else by no text, a note standing in its place', () => {
|
||||
test('shows an image with no URL by its alt, else nothing, a note standing in its place', () => {
|
||||
assert.deepEqual(shownImage({ attrs: { alt: 'The moon', type: 'file' }, type: 'media' }, target), { after: undefined, link: undefined, text: 'The moon' })
|
||||
assert.deepEqual(shownImage({ attrs: { type: 'file' }, type: 'mediaInline' }, undefined), { after: undefined, link: undefined, text: undefined })
|
||||
assert.equal(shownImage({ attrs: { type: 'file' }, type: 'mediaInline' }, undefined), undefined)
|
||||
assert.deepEqual(shownImage({ attrs: { alt: 'The moon', type: 'external', url: ' ' }, type: 'media' }, undefined), { after: undefined, link: undefined, text: 'The moon' })
|
||||
})
|
||||
|
||||
|
||||
@@ -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 }
|
||||
|
||||
Reference in New Issue
Block a user