mirror of
https://github.com/larvit/adf-codec.git
synced 2026-11-19 06:35:44 +01:00
Group mark runs by one rule, insideRun, that both writers and the portable reducer ask
This commit is contained in:
@@ -2,7 +2,7 @@ import type { AdfAttributes, AdfMark, AdfNode } from '../adf/document.ts'
|
||||
import type { AttributeVocabulary } from '../adf/attribute-vocabulary.ts'
|
||||
import type { LinkDefinition, TitleEscapes } from './commonmark/link-syntax.ts'
|
||||
import type { MarkType } from '../adf/mark-attributes.ts'
|
||||
import { emptyKeys, nodeAttrs, nodeMarks } from '../adf/document.ts'
|
||||
import { emptyKeys, identicalMark, nodeAttrs, nodeMarks } from '../adf/document.ts'
|
||||
import { escapeUnbalanced, spellLinkTarget } from './commonmark/link-syntax.ts'
|
||||
import { holdsDirectivePrefix, spellAttributes, spellVocabulary } from './directive/syntax.ts'
|
||||
import { holdsEntityReference } from './commonmark/entity-references.ts'
|
||||
@@ -17,6 +17,9 @@ export type MarkSpelling = Spelling & { attributes: AttributeVocabulary }
|
||||
|
||||
export type CommonMarkLink = { form: 'autolink'; target?: undefined } | { form: 'inline'; target: string }
|
||||
|
||||
// An inline node inside the runs of its first `outer` marks.
|
||||
export type RunNode = { node: AdfNode; outer: number }
|
||||
|
||||
const markSpellings: Readonly<Record<MarkType, Spelling>> = {
|
||||
border: { kind: 'directive' },
|
||||
code: { kind: 'code' },
|
||||
@@ -41,6 +44,12 @@ export function isEmphasis(mark: AdfMark): boolean {
|
||||
return markSpelling(mark.type)?.kind === 'emphasis'
|
||||
}
|
||||
|
||||
// spec/flavour.md, Marks. The writers and the portable reducer group runs alike only while both ask this.
|
||||
export function insideRun({ node, outer }: RunNode, mark: AdfMark): RunNode | undefined {
|
||||
const held = nodeMarks(node)[outer]
|
||||
return held !== undefined && identicalMark(held, mark) ? { node, outer: outer + 1 } : undefined
|
||||
}
|
||||
|
||||
export function linkMark(definition: LinkDefinition): AdfMark {
|
||||
return linkMarkFrom(toLinkAttrs(definition))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user