mirror of
https://github.com/larvit/adf-codec.git
synced 2026-11-17 21:55:44 +01:00
20 lines
1.2 KiB
TypeScript
20 lines
1.2 KiB
TypeScript
import type { AdfNode } from '../adf/document.ts'
|
|
import type { LinkDefinition } from './commonmark/link-syntax.ts'
|
|
import { linkMark } from './mark-spellings.ts'
|
|
|
|
// spec/flavour.md, The CommonMark image: `` reads to `centeredImage([externalMedia(alt, url)])`, the only shape `adfToLosslessMarkdown` writes as ``.
|
|
export function centeredImage(content: AdfNode[]): AdfNode {
|
|
return { attrs: { layout: 'center' }, content, type: 'mediaSingle' }
|
|
}
|
|
|
|
// `` builds no `alt`, so a media holding an empty one takes the directive form.
|
|
export function externalMedia(alt: string, url: string, link?: LinkDefinition): AdfNode {
|
|
const media: AdfNode = { attrs: alt === '' ? { type: 'external', url } : { alt, type: 'external', url }, type: 'media' }
|
|
return link === undefined ? media : { ...media, marks: [linkMark(link)] }
|
|
}
|
|
|
|
// The ` (image)` after a link for an image inside it, as the readers build it (spec/flavour.md, The CommonMark image) and `adfToPortableMarkdown` writes it; `link` builds the linked word `image`.
|
|
export function imageAside(link: (text: string) => AdfNode[]): AdfNode[] {
|
|
return [{ text: ' (', type: 'text' }, ...link('image'), { text: ')', type: 'text' }]
|
|
}
|