3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-19 22:55:44 +01:00

Ship adfToHtml: semantic HTML for the CommonMark blocks and marks, an adf-carry element for the rest

This commit is contained in:
2026-10-23 12:50:48 +02:00
committed by Lillem4n
parent 33ef8db768
commit 6fe36d5947
33 changed files with 826 additions and 147 deletions
+13 -8
View File
@@ -7,7 +7,7 @@ import { escapeUnbalanced, spellLinkTarget } from './commonmark/link-syntax.ts'
import { holdsDirectivePrefix, spellAttributes, spellVocabulary } from './directive/syntax.ts'
import { holdsEntityReference } from './commonmark/entity-references.ts'
import { isAutolink } from './commonmark/grammar.ts'
import { isMarkType, markAttributes } from '../adf/mark-attributes.ts'
import { isMarkType, linkTarget, linkTargetMark, markAttributes, type LinkTarget } from '../adf/mark-attributes.ts'
import { spellEmptyKeys } from './directive/empty-keys.ts'
import { vocabularyPairs } from '../adf/attribute-vocabulary.ts'
@@ -37,16 +37,21 @@ export function markSpelling(type: string): MarkSpelling | undefined {
return { attributes, kind: spelling.kind }
}
export function linkMark({ destination, title }: LinkDefinition): AdfMark {
return { attrs: title === undefined ? { href: destination } : { href: destination, title }, type: 'link' }
export function linkMark(definition: LinkDefinition): AdfMark {
return linkTargetMark(definitionTarget(definition))
}
export function definitionTarget({ destination, title }: LinkDefinition): LinkTarget {
return title === undefined ? { href: destination } : { href: destination, title }
}
export function linkDefinition(attrs: AdfAttributes): LinkDefinition | undefined {
const destination = linkHref(attrs)
const title = attrs['title']
if (destination === undefined) return undefined
if (title === undefined) return { destination }
return typeof title === 'string' ? { destination, title } : undefined
const target = linkTarget(attrs)
return target === undefined ? undefined : targetDefinition(target)
}
export function targetDefinition({ href, title }: LinkTarget): LinkDefinition {
return title === undefined ? { destination: href } : { destination: href, title }
}
export function linkHref(attrs: AdfAttributes): string | undefined {