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
@@ -431,6 +431,7 @@ test('refuses marks and attributes nested deeper than the emitter carries', () =
const markedCode: AdfNode = { content: [{ text: 'x', type: 'text' }], marks: [{ attrs: { deep: nested(largestNesting - 2) }, type: 'em' }], type: 'codeBlock' }
assert.equal(markdown(adfToLosslessMarkdown(document(markedCode))), deeper('marks', 'codeBlock'))
roundTrips(marked(largestNesting - 3))
roundTrips({ ...marked(0), marks: [{ attrs: { sources: nested(largestNesting) }, type: 'dataConsumer' }] })
})
test('escapes a literal delimiter that would merge with an emitted one', () => {
@@ -1,10 +1,9 @@
import type { AdfNode } from '../../adf/document.ts'
import type { BlockNodeModel } from '../../adf/block-nodes.ts'
import { attributeNestingMessage, nodeAttrs, nodeMarks } from '../../adf/document.ts'
import { blockArgument, markValues, marksAttribute, spellBlockMarks } from '../block-directive.ts'
import { blockArgument, marksAttribute, spellBlockMarks } from '../block-directive.ts'
import { failure, success, type ConvertErrorPath, type Result } from '../../result.ts'
import { isBareToken, spellAttributes, spellDirectiveOpener, spellVocabulary } from '../directive-syntax.ts'
import { overNested } from '../../json-value.ts'
import { spellEmptyKeys } from '../empty-keys.ts'
import { vocabularyPairs } from '../../adf/attribute-vocabulary.ts'
@@ -18,8 +17,9 @@ export function spellBlockDirectiveOpener(node: AdfNode, model: BlockNodeModel,
const spelledPairs = [...spellVocabulary(pairs), ...spellEmptyKeys(node)]
const marks = nodeMarks(node)
if (marks.length > 0) {
if (overNested(markValues(marks))) return failure('unsupported-nesting-depth', attributeNestingMessage(marksAttribute, node.type), path)
spelledPairs.push([marksAttribute, spellBlockMarks(marks)])
const spelling = spellBlockMarks(marks)
if (spelling === undefined) return failure('unsupported-nesting-depth', attributeNestingMessage(marksAttribute, node.type), path)
spelledPairs.push([marksAttribute, spelling])
}
return success(spellDirectiveOpener(node.type, slot.argument, spellAttributes(spelledPairs)))
}