Answer the second stability pass: the emitter's own refusal, and the comparator's third arm
CI / gate (push) Successful in 5s

This commit is contained in:
2026-09-01 14:34:02 +02:00
parent dcb4d67b6c
commit fba826ed89
7 changed files with 24 additions and 13 deletions
+2 -1
View File
@@ -107,7 +107,8 @@ export function unknownDirectiveFault(name: string): ConvertFault {
}
function keyOrder(left: string, right: string): number {
return left < right ? -1 : 1
if (left < right) return -1
return left > right ? 1 : 0
}
function quote(text: string): string {
+4 -3
View File
@@ -86,9 +86,10 @@ function emitBlock(node: AdfNode, path: ConvertErrorPath, depth: number): Result
return emitDirectiveBlock(node, directive, path, depth)
}
// The plain-versus-directive choice is the emitter's; input reads it back rather than restating it (AGENTS.md §11).
export function spellsCommonMark(node: AdfNode, path: ConvertErrorPath, depth: number): boolean {
return readableBlock(node, path, depth) !== undefined
export function commonMarkSpelling(node: AdfNode, path: ConvertErrorPath, depth: number): Result<null> | undefined {
const readable = readableBlock(node, path, depth)
if (readable === undefined) return undefined
return readable.ok ? success(null) : readable
}
function readableBlock(node: AdfNode, path: ConvertErrorPath, depth: number): Result<EmittedBlock> | undefined {
+6 -1
View File
@@ -148,7 +148,6 @@ test('reads the three directive forms into the nodes the tables name', () => {
assert.deepEqual(content(markdownToAdf('Part:hardBreak{}.\n')), [{ content: [text('Part'), hardBreak(), text('.')], type: 'paragraph' }])
})
// The emitter's plain-versus-directive choice, read backwards: only the form it picks parses.
test('names the directive form a node CommonMark spells refuses', () => {
const named = (type: string): string => `unsupported-node-shape: ${type} takes the CommonMark spelling, not the directive form`
assert.equal(content(markdownToAdf('::rule\n')), named('rule'))
@@ -160,6 +159,12 @@ test('names the directive form a node CommonMark spells refuses', () => {
assert.deepEqual(content(markdownToAdf('::::bulletList\n:::listItem\n---\n:::\n::::\n')), [bulletList(item({ type: 'rule' }))])
})
// The spelling the emitter refuses gives the emitter's own error, never a second name for it.
test('gives back the refusal the CommonMark spelling itself raises', () => {
const nested = '::::::::bulletList\n:::::::listItem\n---\n\n::::::bulletList\n:::::listItem\n---\n\n::::bulletList\n:::listItem\n---\n:::\n::::\n:::::\n::::::\n:::::::\n::::::::\n'
assert.equal(code(markdownToAdf(nested)), 'unspelled-block-separation')
})
test('names the directive name no node reads back to', () => {
assert.equal(code(markdownToAdf(':::widget info\nx\n:::\n')), 'unknown-directive-name')
assert.equal(content(markdownToAdf('::widget\n')), 'unknown-directive-name: the directive name widget reads back to no node')
+5 -5
View File
@@ -3,12 +3,12 @@ import type { Block, DirectiveBlock } from './blocks.ts'
import type { BlockDirectiveNode } from './directive-nodes.ts'
import type { LinkDefinitions } from './inline-content.ts'
import { carryName } from '../opaque-carry.ts'
import { commonMarkSpelling } from '../emit/adf-to-markdown.ts'
import { failure, faulted, success, type ConvertErrorPath, type Result } from '../../result.ts'
import { largestNesting } from '../../nesting.ts'
import { parseBlocks } from './blocks.ts'
import { parseInlineContent } from './inline-content.ts'
import { readBlockDirectiveNode } from './directive-nodes.ts'
import { spellsCommonMark } from '../emit/adf-to-markdown.ts'
export function markdownToAdf(markdown: string): Result<AdfDocument> {
const parsed = parseBlocks(markdown)
@@ -58,10 +58,10 @@ function directiveNode(block: DirectiveBlock, definitions: LinkDefinitions, path
if (!read.ok) return read
const built = directiveBody(read.value, block.blocks, definitions, path, depth)
if (!built.ok) return built
if (spellsCommonMark(built.value, path, depth)) {
return failure('unsupported-node-shape', `${built.value.type} takes the CommonMark spelling, not the directive form`, path)
}
return built
const readable = commonMarkSpelling(built.value, path, depth)
if (readable === undefined) return built
if (!readable.ok) return readable
return failure('unsupported-node-shape', `${built.value.type} takes the CommonMark spelling, not the directive form`, path)
}
function directiveBody(read: BlockDirectiveNode, blocks: Block[] | undefined, definitions: LinkDefinitions, path: ConvertErrorPath, depth: number): Result<AdfNode> {