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

Answer architecture round 1: 2 🔴, 5 🟡; nesting counts the JSON fallback alone, one mark attrs read and spell, one mark table, a malformed mark is unsupported-node-shape, the old colwidth names the comma list, README and notes name the attrs fallback

This commit is contained in:
2026-10-14 10:09:06 +02:00
committed by Lillem4n
parent 9e9d88a8e4
commit c8ea357fa7
16 changed files with 88 additions and 68 deletions
+8 -2
View File
@@ -9,11 +9,17 @@ export type VocabularyValue =
| { kind: 'boolean'; value: boolean }
| { kind: 'json'; value: JsonValue }
| { kind: 'number'; value: number }
| { kind: 'numbers'; value: number[] }
| { kind: 'numbers'; value: NumberList }
| { kind: 'string'; value: string }
export type VocabularyPair = VocabularyValue & { key: string }
export type NumberList = [number, ...number[]]
export function isNumberList(value: unknown): value is NumberList {
return Array.isArray(value) && value.length > 0 && value.every((item) => typeof item === 'number')
}
export function vocabularyPairs(attrs: AdfAttributes, vocabulary: AttributeVocabulary, spelledElsewhere: readonly string[]): VocabularyPair[] | undefined {
const pairs: VocabularyPair[] = []
for (const [key, value] of Object.entries(attrs)) {
@@ -30,7 +36,7 @@ export function vocabularyPairs(attrs: AdfAttributes, vocabulary: AttributeVocab
function vocabularyPair(key: string, value: JsonValue, kind: AttributeKind): VocabularyPair | undefined {
if (kind === 'boolean') return typeof value === 'boolean' ? { key, kind, value } : undefined
if (kind === 'number') return typeof value === 'number' ? { key, kind, value } : undefined
if (kind === 'numbers') return Array.isArray(value) && value.length > 0 && value.every((item) => typeof item === 'number') ? { key, kind, value } : undefined
if (kind === 'numbers') return isNumberList(value) ? { key, kind, value } : undefined
if (kind === 'string') return typeof value === 'string' ? { key, kind, value } : undefined
return { key, kind, value }
}
+1 -5
View File
@@ -21,14 +21,10 @@ export const markAttributes = {
underline: {},
} satisfies Readonly<Record<string, AttributeVocabulary>>
const blockMarkVocabularies: ReadonlyMap<string, AttributeVocabulary> = new Map(Object.entries(blockMarkAttributes))
export const markVocabularies: ReadonlyMap<string, AttributeVocabulary> = new Map([...Object.entries(blockMarkAttributes), ...Object.entries(markAttributes)])
export type MarkType = keyof typeof markAttributes
export function isMarkType(type: string): type is MarkType {
return Object.hasOwn(markAttributes, type)
}
export function markVocabulary(type: string): AttributeVocabulary | undefined {
return isMarkType(type) ? markAttributes[type] : blockMarkVocabularies.get(type)
}