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

Answer prose round 1: 0 🔴, 6 🟡; the changelog names what breaks, the fallback reads as untyped mark, attribute or value, the spec's value list and marks paragraph split, messages name the JSON array to write

This commit is contained in:
2026-10-14 10:28:50 +02:00
committed by Lillem4n
parent 168ca1cea2
commit aefcd4b9e3
10 changed files with 37 additions and 35 deletions
-1
View File
@@ -1,6 +1,5 @@
import type { AttributeVocabulary } from './attribute-vocabulary.ts'
// Marks only a block's marks key holds, so no inline spelling names them.
export const blockMarkAttributes = {
alignment: { align: 'string' },
breakout: { mode: 'string', width: 'number' },
+1 -1
View File
@@ -41,7 +41,7 @@ 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, `undefined` where that array nests past largestNesting.
// `undefined` where the JSON array nests past largestNesting.
export function spellBlockMarks(marks: readonly AdfMark[]): string | undefined {
const named: string[] = []
for (const mark of marks) {
+1 -1
View File
@@ -74,7 +74,7 @@ export function spellMarkAttributes(mark: AdfMark, spelling: MarkSpelling): stri
return emptyKeys(mark).length > 0 && spelling.kind !== 'directive' ? undefined : spellMarkVocabulary(mark, spelling.attributes)
}
// `undefined` where an attribute is one the vocabulary does not type.
// `undefined` where the vocabulary lacks an attribute or types its value otherwise.
export function spellMarkVocabulary(mark: AdfMark, vocabulary: AttributeVocabulary): string | undefined {
const pairs = vocabularyPairs(nodeAttrs(mark), vocabulary, [])
return pairs === undefined ? undefined : spellAttributes([...spellVocabulary(pairs), ...spellEmptyKeys(mark)])
+2 -2
View File
@@ -132,7 +132,7 @@ function readNamedMark(type: string, text: string, index: number, path: ConvertE
const name = readDirectiveName(text, index)
if (name === undefined) return failure('unsupported-node-shape', unnamedMarks(type), path)
const vocabulary = markVocabularies.get(name)
if (vocabulary === undefined) return failure('unsupported-node-shape', `the ${marksAttribute} attribute of ${type} names ${name}, no mark the flavour lists: spell an unlisted mark in the JSON array`, path)
if (vocabulary === undefined) return failure('unsupported-node-shape', `the ${marksAttribute} attribute of ${type} names ${name}, no mark the flavour lists: write the marks as their JSON array, marks="[{\\"type\\":\\"${name}\\"}]"`, path)
const start = index + name.length
const attributes = text.charAt(start) === '{' ? readAttributes(text, start) : { value: { attributes: new Map<string, DirectiveValue>(), end: start } }
if (attributes.fault !== undefined) {
@@ -145,7 +145,7 @@ function readNamedMark(type: string, text: string, index: number, path: ConvertE
}
function unnamedMarks(type: string): string {
return `the ${marksAttribute} attribute of ${type} names each mark with its {attrs}, one space apart: this one does not`
return `the ${marksAttribute} attribute of ${type} names its marks one space apart, each as its type and any {attrs}: this one does not`
}
function namedNode(type: string, attrs: AdfAttributes, marks: readonly AdfMark[] | undefined, empty: ReadonlySet<EmptyKey>): AdfNode {
+2 -2
View File
@@ -550,7 +550,7 @@ test('reads the reserved marks key as a JSON array where a mark is one the table
test('names the marks key no marks read back from', () => {
const array = 'unsupported-node-shape: the marks attribute of rule is its marks array in canonical JSON: this one is not'
const named = 'unsupported-node-shape: the marks attribute of rule names each mark with its {attrs}, one space apart: this one does not'
const named = 'unsupported-node-shape: the marks attribute of rule names its marks one space apart, each as its type and any {attrs}: this one does not'
assert.equal(content(losslessMarkdownToAdf('!adf:rule {marks="[]"}\n')), array)
assert.equal(content(losslessMarkdownToAdf('!adf:rule {marks="[1]"}\n')), array)
assert.equal(content(losslessMarkdownToAdf('!adf:rule {marks="{}"}\n')), named)
@@ -562,7 +562,7 @@ test('names the marks key no marks read back from', () => {
assert.equal(content(losslessMarkdownToAdf('!adf:rule {marks="breakout{mode=wide"}\n')), inBreakout('the {attrs} closing brace is missing'))
assert.equal(content(losslessMarkdownToAdf('!adf:rule {marks="em{attrs=empty}strong"}\n')), named)
assert.equal(content(losslessMarkdownToAdf('!adf:rule {marks="em{attrs=x}"}\n')), 'unsupported-node-shape: the reserved key attrs takes only the value empty: this one spells attrs=x')
assert.equal(content(losslessMarkdownToAdf('!adf:rule {marks=x}\n')), 'unsupported-node-shape: the marks attribute of rule names x, no mark the flavour lists: spell an unlisted mark in the JSON array')
assert.equal(content(losslessMarkdownToAdf('!adf:rule {marks=x}\n')), 'unsupported-node-shape: the marks attribute of rule names x, no mark the flavour lists: write the marks as their JSON array, marks="[{\\"type\\":\\"x\\"}]"')
assert.equal(content(losslessMarkdownToAdf('!adf:rule {marks="breakout{width=wide}"}\n')), 'unsupported-node-shape: the width attribute of breakout is no number')
assert.equal(content(losslessMarkdownToAdf('!adf:rule {marks="breakout{bogus=1}"}\n')), 'unsupported-node-shape: breakout holds no bogus attribute: this one spells it')
})