Read the three directive forms, their attributes and the fences that nest them
CI / gate (push) Successful in 5s

This commit is contained in:
2026-09-01 08:12:03 +02:00
parent 4ad80e79c5
commit f328ed4cab
24 changed files with 581 additions and 89 deletions
+8 -12
View File
@@ -1,10 +1,11 @@
import type { AdfDocument, AdfNode } from '../../adf/document.ts'
import type { Block, ClaimedConstruct } from './blocks.ts'
import type { Block } from './blocks.ts'
import type { LinkDefinitions } from './inline-content.ts'
import { failure, 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 { unknownDirectiveFault } from '../directive-syntax.ts'
export function markdownToAdf(markdown: string): Result<AdfDocument> {
const parsed = parseBlocks(markdown)
@@ -30,10 +31,14 @@ function blockNode(block: Block, definitions: LinkDefinitions, path: ConvertErro
return containerNode({ type: 'blockquote' }, block.blocks, definitions, path, depth)
case 'bulletList':
return listNode({ type: 'bulletList' }, block.items, definitions, path, depth)
case 'claim':
return claimFailure(block.construct, path)
case 'code':
return success(codeBlockNode(block.language, block.text))
case 'directive': {
const fault = unknownDirectiveFault(block.name)
return failure(fault.code, fault.message, path)
}
case 'fault':
return failure(block.fault.code, block.fault.message, path)
case 'heading':
return contentNode({ attrs: { level: block.level }, type: 'heading' }, block.text, definitions, path)
case 'html':
@@ -63,15 +68,6 @@ function listNode(node: AdfNode, items: readonly Block[][], definitions: LinkDef
return success({ ...node, content })
}
function claimFailure(construct: ClaimedConstruct, path: ConvertErrorPath): Result<AdfNode> {
switch (construct) {
case 'directive':
return failure('malformed-directive', 'the line claims a directive and parses as none', path)
case 'pipe-table':
return failure('malformed-pipe-table', 'the line claims a pipe table and parses as none', path)
}
}
function codeBlockNode(language: string, text: string): AdfNode {
const node: AdfNode = language === '' ? { type: 'codeBlock' } : { attrs: { language }, type: 'codeBlock' }
return text === '' ? node : { ...node, content: [{ text, type: 'text' }] }