Fix the false claims round one found, and refuse the content a code span dropped
CI / gate (push) Successful in 5s

This commit is contained in:
2026-08-27 11:42:43 +02:00
parent 7035e42d1d
commit a5b8a4654f
8 changed files with 59 additions and 19 deletions
+4 -1
View File
@@ -317,9 +317,12 @@ test('refuses the characters CommonMark rewrites', () => {
assert.equal(code(adfToMarkdown(document({ content: [{ text: '', type: 'text' }], type: 'codeBlock' }))), 'unsupported-node-shape')
})
test('refuses a text node carrying no text at all', () => {
test('refuses a text node the spelling would empty out', () => {
const nested: AdfNode[] = [{ text: 'lost', type: 'text' }]
assert.equal(code(adfToMarkdown(document(paragraph({ text: '', type: 'text' })))), 'unsupported-node-shape')
assert.equal(code(adfToMarkdown(document(paragraph({ marks: [{ type: 'code' }], text: '', type: 'text' })))), 'unsupported-node-shape')
assert.equal(code(adfToMarkdown(document(paragraph({ content: nested, text: 'x', type: 'text' })))), 'unsupported-node-shape')
assert.equal(code(adfToMarkdown(document(paragraph({ content: nested, marks: [{ type: 'code' }], text: 'x', type: 'text' })))), 'unsupported-node-shape')
})
test('carries a mark run whose edge holds whitespace CommonMark flanking counts', () => {
+3 -5
View File
@@ -110,13 +110,11 @@ function commonMarkContainer(body: Result<EmittedBody>): Result<EmittedBlock> {
function emitDirectiveBlock(node: AdfNode, directive: BlockDirective, path: ConvertErrorPath, depth: number): Result<EmittedBlock> {
if (node.text !== undefined) return failure('unsupported-node-shape', `a ${node.type} carries no text`, path)
const content = node.content ?? []
if (directive.body === 'none' && content.length > 0) return failure('unsupported-node-shape', `a ${node.type} holds no content`, path)
const header = spellDirectiveHeader(node, directive)
if (header === undefined) return commonMarkLine(carriedBlock(node, path))
const content = node.content ?? []
if (directive.body === 'none') {
if (content.length > 0) return failure('unsupported-node-shape', `a ${node.type} holds no content`, path)
return success({ fenceColons: 2, spelling: 'directive', text: `::${header}` })
}
if (directive.body === 'none') return success({ fenceColons: 2, spelling: 'directive', text: `::${header}` })
const body = directive.body === 'inline' ? emitInlineBody(content, path) : emitBlocks(content, 'directive', path, depth + 1)
if (!body.ok) return body
const fenceColons = Math.max(3, body.value.fenceColons + 1)
+2 -1
View File
@@ -48,7 +48,7 @@ export function tryImageLine(alt: string | undefined, href: string, path: Conver
return attempt.ok ? attempt.value.line : undefined
}
// A demand names a run no spelling holds, and a carried node joins no run, so every pass carries one more node.
// A demand names a run no spelling holds, and a carried node joins no run, so every pass carries at least one more node.
function emitLine(nodes: readonly AdfNode[], container: LineContainer, path: ConvertErrorPath): Result<EmittedLine> {
const carried = new Set<number>()
for (;;) {
@@ -262,6 +262,7 @@ function emitCodeSpan(nodes: readonly AdfNode[], depth: number, range: NodeRange
for (const node of nodes) {
if (node.type !== 'text' || (node.marks ?? []).length !== depth + 1) return success({ carry: range })
if (typeof node.text !== 'string' || node.text === '') return failure('unsupported-node-shape', 'a text node holds text', path)
if ((node.content ?? []).length > 0) return failure('unsupported-node-shape', 'a text node holds no content', path)
text += node.text
}
if (/[\n\r]/.test(text)) return success({ carry: range })