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

Spell colwidth as a comma list and a block's marks by name

This commit is contained in:
2026-10-14 09:59:21 +02:00
committed by Lillem4n
parent 1c7518aea1
commit e882b5de7a
18 changed files with 209 additions and 59 deletions
+17 -2
View File
@@ -2,9 +2,12 @@ import type { AdfMark } from '../adf/document.ts'
import type { BlockType } from '../adf/block-nodes.ts'
import type { JsonValue } from '../json-value.ts'
import { blockNodeModel } from '../adf/block-nodes.ts'
import { isAdfMark } from '../adf/document.ts'
import { isAdfMark, nodeAttrs } from '../adf/document.ts'
import { markVocabulary } from '../adf/mark-attributes.ts'
import { serializeCanonicalJson } from '../canonical-json.ts'
import { spellAttributes, spellDirectiveOpener } from './directive-syntax.ts'
import { spellAttributes, spellDirectiveOpener, spellJsonAttribute, spellStringAttribute, spellVocabulary } from './directive-syntax.ts'
import { spellEmptyKeys } from './empty-keys.ts'
import { vocabularyPairs } from '../adf/attribute-vocabulary.ts'
const argumentByType = new Map(
Object.entries({
@@ -38,6 +41,18 @@ export function markValues(marks: readonly AdfMark[]): JsonValue {
return marks.map((mark) => (mark.attrs === undefined ? { type: mark.type } : { attrs: mark.attrs, type: mark.type }))
}
// spec/flavour.md, Block nodes: each mark by name, else the whole array as JSON where one mark's type or attrs no table types.
export function spellBlockMarks(marks: readonly AdfMark[]): string {
const named: string[] = []
for (const mark of marks) {
const vocabulary = markVocabulary(mark.type)
const pairs = vocabulary === undefined ? undefined : vocabularyPairs(nodeAttrs(mark), vocabulary, [])
if (pairs === undefined) return spellJsonAttribute(markValues(marks))
named.push(`${mark.type}${spellAttributes([...spellVocabulary(pairs), ...spellEmptyKeys(mark)])}`)
}
return spellStringAttribute(named.join(' '))
}
export function readMarkValues(value: JsonValue): AdfMark[] | undefined {
if (!Array.isArray(value) || value.length === 0) return undefined
const marks: AdfMark[] = []