From 67c3345fd23f742984e1627e95e58c44e21fb083 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 21 Sep 2026 21:45:11 +0200 Subject: [PATCH] 21 - the table's row is the node's model, never the node --- src/adf-schema.test.ts | 4 +-- src/adf/block-nodes.ts | 6 ++--- src/adf/inline-nodes.ts | 6 ++--- src/markdown-property.test.ts | 14 +++++----- src/markdown/block-directive-forms.ts | 8 +++--- src/markdown/emit/adf-to-markdown.ts | 26 +++++++++---------- src/markdown/emit/block-directive-spelling.ts | 6 ++--- .../emit/inline-directive-spelling.ts | 6 ++--- src/markdown/emit/inline-line.ts | 24 ++++++++--------- src/markdown/parse/directive-nodes.ts | 26 +++++++++---------- src/markdown/parse/inline-content.ts | 4 +-- src/property-harness.ts | 22 ++++++++-------- todo-history.md | 15 ++++++----- todo.md | 13 ++++++++-- 14 files changed, 96 insertions(+), 84 deletions(-) diff --git a/src/adf-schema.test.ts b/src/adf-schema.test.ts index c0d8325..e373afa 100644 --- a/src/adf-schema.test.ts +++ b/src/adf-schema.test.ts @@ -78,8 +78,8 @@ test("the ADF JSON Schemas hold no type the tables leave unspelled, the pinned c function spelled(): Spelled[] { return [ - ...Object.entries(blockNodes).map(([type, entry]) => spelledType(type, entry.attributes, blockArgument(type))), - ...Object.entries(inlineNodes).map(([type, entry]) => spelledType(type, entry.attributes)), + ...Object.entries(blockNodes).map(([type, model]) => spelledType(type, model.attributes, blockArgument(type))), + ...Object.entries(inlineNodes).map(([type, model]) => spelledType(type, model.attributes)), ...Object.entries(markAttributes).map(([type, attributes]) => spelledType(type, attributes)), ] } diff --git a/src/adf/block-nodes.ts b/src/adf/block-nodes.ts index 1a39620..7db6457 100644 --- a/src/adf/block-nodes.ts +++ b/src/adf/block-nodes.ts @@ -1,6 +1,6 @@ import type { AttributeVocabulary } from './attribute-vocabulary.ts' -export type BlockNode = { +export type BlockNodeModel = { attributes: AttributeVocabulary contentModel: 'block' | 'code' | 'inline' | 'none' } @@ -80,11 +80,11 @@ export const blockNodes = { tableRow: { attributes: localIdAttributes, contentModel: 'block' }, taskItem: { attributes: localIdAttributes, contentModel: 'inline' }, taskList: { attributes: localIdAttributes, contentModel: 'block' }, -} satisfies Readonly> +} satisfies Readonly> export type BlockType = keyof typeof blockNodes -export function blockNodeNamed(type: string): BlockNode | undefined { +export function blockNodeModel(type: string): BlockNodeModel | undefined { return isBlockType(type) ? blockNodes[type] : undefined } diff --git a/src/adf/inline-nodes.ts b/src/adf/inline-nodes.ts index 1850018..998ae87 100644 --- a/src/adf/inline-nodes.ts +++ b/src/adf/inline-nodes.ts @@ -1,11 +1,11 @@ import type { AttributeVocabulary } from './attribute-vocabulary.ts' -export type InlineNode = { +export type InlineNodeModel = { attributes: AttributeVocabulary textAttribute?: string } -export const inlineNodes: Readonly> = { +export const inlineNodes: Readonly> = { date: { attributes: { localId: 'string', timestamp: 'string' } }, emoji: { attributes: { id: 'string', localId: 'string', shortName: 'string', text: 'string' }, textAttribute: 'text' }, hardBreak: { attributes: { localId: 'string', text: 'string' } }, @@ -27,6 +27,6 @@ export const inlineNodes: Readonly> = { status: { attributes: { color: 'string', localId: 'string', style: 'string', text: 'string' }, textAttribute: 'text' }, } -export function inlineNodeNamed(type: string): InlineNode | undefined { +export function inlineNodeModel(type: string): InlineNodeModel | undefined { return Object.hasOwn(inlineNodes, type) ? inlineNodes[type] : undefined } diff --git a/src/markdown-property.test.ts b/src/markdown-property.test.ts index f42e142..b69dd72 100644 --- a/src/markdown-property.test.ts +++ b/src/markdown-property.test.ts @@ -50,7 +50,7 @@ const fixpointFloor = 600 const gateRuns = 1000 const markdownMarkTypes = new Set(Object.keys(markAttributes).filter((type) => markSpelling(type)?.kind !== 'directive')) -const vocabularies = [...Object.values(blockNodes).map((blockNode) => blockNode.attributes), ...Object.values(inlineNodes).map((inlineNode) => inlineNode.attributes), ...Object.values(markAttributes)] +const vocabularies = [...Object.values(blockNodes).map((model) => model.attributes), ...Object.values(inlineNodes).map((model) => model.attributes), ...Object.values(markAttributes)] const attributeKeys = [ ...new Set([...vocabularies.flatMap((vocabulary) => Object.keys(vocabulary)), ...Object.keys(blockNodes).flatMap((type) => blockArgument(type) ?? []), marksAttribute, 'json', textDirectiveName]), ] @@ -233,9 +233,9 @@ function inlineMarkdown(hostile: boolean): InlineMarkdown { }, { arbitrary: fc.oneof( - ...Object.entries(inlineNodes).map(([name, inlineNode]) => + ...Object.entries(inlineNodes).map(([name, model]) => fc - .tuple(inlineNode.textAttribute === undefined ? fc.constant(null) : fc.option(hostile ? word : prose), tableAttributes(inlineNode.attributes, inlineNode.textAttribute)) + .tuple(model.textAttribute === undefined ? fc.constant(null) : fc.option(hostile ? word : prose), tableAttributes(model.attributes, model.textAttribute)) .map(([slot, attrs]) => (slot === null ? spellInlineLeafDirective(name, attrs) : `${spellInlineDirectiveOpener(name)}${slot}]${attrs}`)), ), ...Object.entries(markAttributes) @@ -328,15 +328,15 @@ function blockMarkdown(hostile: boolean, { inlines, oneLine }: InlineMarkdown, { const blockDepth = fc.createDepthIdentifier() const { blocks } = fc.letrec<{ block: string; blocks: string }>((tie) => { const bodyByModel = { block: fc.oneof(tie('blocks'), fc.constant('')), code: fencedCode, inline: fc.oneof(oneLine, fc.constant('')) } - const tableDirectives = Object.entries(blockNodes).map(([name, blockNode]) => { + const tableDirectives = Object.entries(blockNodes).map(([name, model]) => { const argument = blockArgument(name) === undefined ? fc.constant(undefined) : fc.oneof({ arbitrary: fc.constantFrom('DONE', 'TODO', 'custom', 'info', 'warning'), weight: 3 }, { arbitrary: bareToken, weight: 1 }) - const attrs = hostile ? fc.oneof({ arbitrary: tableAttributes(blockNode.attributes), weight: 4 }, { arbitrary: hostileAttributes, weight: 1 }) : tableAttributes(blockNode.attributes) - if (blockNode.contentModel === 'none') return fc.tuple(argument, attrs).map(([held, spelled]) => spellDirectiveOpener(name, held, spelled)) + const attrs = hostile ? fc.oneof({ arbitrary: tableAttributes(model.attributes), weight: 4 }, { arbitrary: hostileAttributes, weight: 1 }) : tableAttributes(model.attributes) + if (model.contentModel === 'none') return fc.tuple(argument, attrs).map(([held, spelled]) => spellDirectiveOpener(name, held, spelled)) return fc - .tuple(argument, attrs, bodyByModel[blockNode.contentModel], hostile ? closerDrift : fc.constant(null)) + .tuple(argument, attrs, bodyByModel[model.contentModel], hostile ? closerDrift : fc.constant(null)) .map(([held, spelled, body, closer]) => container(spellDirectiveOpener(name, held, spelled), body, closer ?? spellDirectiveCloser(name))) }) return { diff --git a/src/markdown/block-directive-forms.ts b/src/markdown/block-directive-forms.ts index 2ce50a0..a12cbb1 100644 --- a/src/markdown/block-directive-forms.ts +++ b/src/markdown/block-directive-forms.ts @@ -1,9 +1,9 @@ -import { blockNodeNamed } from '../adf/block-nodes.ts' +import { blockNodeModel } from '../adf/block-nodes.ts' import { listBreakName } from './list-break.ts' export function blockDirectiveForm(name: string): 'container' | 'leaf' | undefined { if (name === listBreakName) return 'leaf' - const blockNode = blockNodeNamed(name) - if (blockNode === undefined) return undefined - return blockNode.contentModel === 'none' ? 'leaf' : 'container' + const model = blockNodeModel(name) + if (model === undefined) return undefined + return model.contentModel === 'none' ? 'leaf' : 'container' } diff --git a/src/markdown/emit/adf-to-markdown.ts b/src/markdown/emit/adf-to-markdown.ts index 08e6762..f0c176a 100644 --- a/src/markdown/emit/adf-to-markdown.ts +++ b/src/markdown/emit/adf-to-markdown.ts @@ -1,8 +1,8 @@ import type { AdfDocument, AdfNode } from '../../adf/document.ts' -import type { BlockNode } from '../../adf/block-nodes.ts' +import type { BlockNodeModel } from '../../adf/block-nodes.ts' import { adfDocumentFault, carriesOnly, nodeAttrs, nodeContent, nodeMarks } from '../../adf/document.ts' import { blockDirectiveForm } from '../block-directive-forms.ts' -import { blockNodeNamed, blockNodes } from '../../adf/block-nodes.ts' +import { blockNodeModel, blockNodes } from '../../adf/block-nodes.ts' import { carriedBlock } from '../opaque-carry.ts' import { emitInlineLine } from './inline-line.ts' import { failure, faulted, success, type ConvertErrorPath, type Result } from '../../result.ts' @@ -87,11 +87,11 @@ function interruptsParagraph(node: AdfNode): boolean { } function emitBlock(node: AdfNode, path: ConvertErrorPath, depth: number, memo: SpellingMemo | undefined): Result { - const blockNode = blockNodeNamed(node.type) - if (blockNode === undefined) return commonMarkLine(carriedBlock(node, path, depth)) + const model = blockNodeModel(node.type) + if (model === undefined) return commonMarkLine(carriedBlock(node, path, depth)) const readable = readableBlock(node, path, depth, memo) if (readable !== undefined) return readable - return emitDirectiveBlock(node, blockNode, path, depth, () => walkBlocks(nodeContent(node), path, depth + 1, memo)) + return emitDirectiveBlock(node, model, path, depth, () => walkBlocks(nodeContent(node), path, depth + 1, memo)) } export function commonMarkSpelling(node: AdfNode, path: ConvertErrorPath, depth: number, memo: SpellingMemo): Result | undefined { @@ -143,18 +143,18 @@ function directivePair(node: AdfNode, opener: string, body: string, headroom: nu return { headroom, spelling: 'directive', text: `${opener}\n${body === '' ? '' : `${body}\n`}${spellDirectiveCloser(node.type)}` } } -function emitDirectiveBlock(node: AdfNode, blockNode: BlockNode, path: ConvertErrorPath, depth: number, walkBody: () => Result): Result { +function emitDirectiveBlock(node: AdfNode, model: BlockNodeModel, path: ConvertErrorPath, depth: number, walkBody: () => Result): Result { if (node.text !== undefined) return failure('unsupported-node-shape', `a ${node.type} carries no text: this one holds text`, path) if (blockDirectiveForm(node.type) === 'leaf' && nodeContent(node).length > 0) return failure('unsupported-node-shape', `a ${node.type} holds no content: this one holds some`, path) - if (blockNode.contentModel === 'code') return emitCodeDirective(node, blockNode, path, depth) - const opener = spellBlockDirectiveOpener(node, blockNode) + if (model.contentModel === 'code') return emitCodeDirective(node, model, path, depth) + const opener = spellBlockDirectiveOpener(node, model) if (opener === undefined) return commonMarkLine(carriedBlock(node, path, depth)) - return emitDirectiveBody(node, blockNode, opener, path, walkBody) + return emitDirectiveBody(node, model, opener, path, walkBody) } -function emitDirectiveBody(node: AdfNode, blockNode: BlockNode, opener: string, path: ConvertErrorPath, walkBody: () => Result): Result { +function emitDirectiveBody(node: AdfNode, model: BlockNodeModel, opener: string, path: ConvertErrorPath, walkBody: () => Result): Result { if (blockDirectiveForm(node.type) === 'leaf') return success({ headroom: Number.POSITIVE_INFINITY, spelling: 'directive', text: opener }) - if (blockNode.contentModel === 'inline') { + if (model.contentModel === 'inline') { const line = emitInlineLine(nodeContent(node), 'paragraph', path) if (!line.ok) return line return success(directivePair(node, opener, line.value)) @@ -184,9 +184,9 @@ function tryCodeBlock(node: AdfNode, path: ConvertErrorPath): Result { +function emitCodeDirective(node: AdfNode, model: BlockNodeModel, path: ConvertErrorPath, depth: number): Result { const slot = languageSlot(nodeAttrs(node)['language']) - const opener = spellBlockDirectiveOpener(node, blockNode, slot.kind === 'attribute' ? [] : ['language']) + const opener = spellBlockDirectiveOpener(node, model, slot.kind === 'attribute' ? [] : ['language']) if (opener === undefined) return commonMarkLine(carriedBlock(node, path, depth)) const text = codeBlockText(node, path) if (!text.ok) return text diff --git a/src/markdown/emit/block-directive-spelling.ts b/src/markdown/emit/block-directive-spelling.ts index 317acb9..5598932 100644 --- a/src/markdown/emit/block-directive-spelling.ts +++ b/src/markdown/emit/block-directive-spelling.ts @@ -1,17 +1,17 @@ import type { AdfNode } from '../../adf/document.ts' -import type { BlockNode } from '../../adf/block-nodes.ts' +import type { BlockNodeModel } from '../../adf/block-nodes.ts' import { blockArgument } from '../block-directive-arguments.ts' import { isBareToken, spellAttributes, spellDirectiveOpener, spellJsonAttribute, spellVocabulary } from '../directive-syntax.ts' import { markValues, marksAttribute } from '../block-directive-marks.ts' import { nodeAttrs, nodeMarks } from '../../adf/document.ts' import { vocabularyPairs } from '../../adf/attribute-vocabulary.ts' -export function spellBlockDirectiveOpener(node: AdfNode, blockNode: BlockNode, spelledByBody: readonly string[] = []): string | undefined { +export function spellBlockDirectiveOpener(node: AdfNode, model: BlockNodeModel, spelledByBody: readonly string[] = []): string | undefined { const argumentAttribute = blockArgument(node.type) const slot = bareArgument(node, argumentAttribute) if (slot === undefined) return undefined const spelled = argumentAttribute === undefined ? spelledByBody : [argumentAttribute, ...spelledByBody] - const pairs = vocabularyPairs(nodeAttrs(node), blockNode.attributes, spelled) + const pairs = vocabularyPairs(nodeAttrs(node), model.attributes, spelled) if (pairs === undefined) return undefined const spelledPairs = spellVocabulary(pairs) const marks = nodeMarks(node) diff --git a/src/markdown/emit/inline-directive-spelling.ts b/src/markdown/emit/inline-directive-spelling.ts index 90b75ad..0680214 100644 --- a/src/markdown/emit/inline-directive-spelling.ts +++ b/src/markdown/emit/inline-directive-spelling.ts @@ -1,10 +1,10 @@ import type { AdfNode } from '../../adf/document.ts' -import type { InlineNode } from '../../adf/inline-nodes.ts' +import type { InlineNodeModel } from '../../adf/inline-nodes.ts' import { nodeAttrs } from '../../adf/document.ts' import { spellAttributes, spellVocabulary } from '../directive-syntax.ts' import { vocabularyPairs } from '../../adf/attribute-vocabulary.ts' -export function spellInlineNodeAttributes(node: AdfNode, inlineNode: InlineNode): string | undefined { - const pairs = vocabularyPairs(nodeAttrs(node), inlineNode.attributes, inlineNode.textAttribute === undefined ? [] : [inlineNode.textAttribute]) +export function spellInlineNodeAttributes(node: AdfNode, model: InlineNodeModel): string | undefined { + const pairs = vocabularyPairs(nodeAttrs(node), model.attributes, model.textAttribute === undefined ? [] : [model.textAttribute]) return pairs === undefined ? undefined : spellAttributes(spellVocabulary(pairs)) } diff --git a/src/markdown/emit/inline-line.ts b/src/markdown/emit/inline-line.ts index 79e2efe..407cf6c 100644 --- a/src/markdown/emit/inline-line.ts +++ b/src/markdown/emit/inline-line.ts @@ -1,12 +1,12 @@ import type { AdfMark, AdfNode } from '../../adf/document.ts' -import type { InlineNode } from '../../adf/inline-nodes.ts' +import type { InlineNodeModel } from '../../adf/inline-nodes.ts' import { assembleInlineLine, isSyntax, type InlineEscaping, type InlineSegment, type LineContainer, type NodeRange } from './line-escaping.ts' import { carriedInline } from '../opaque-carry.ts' import { claimsLine, holdsNullCharacter, trimTrailingSpace } from '../commonmark/grammar.ts' import { commonMarkLink, linkHref, markSpelling, spellMarkAttributes } from '../mark-spellings.ts' import { escapeUnbalanced, spellDestination } from '../commonmark/link-syntax.ts' import { failure, faulted, success, type ConvertErrorPath, type Result } from '../../result.ts' -import { inlineNodeNamed } from '../../adf/inline-nodes.ts' +import { inlineNodeModel } from '../../adf/inline-nodes.ts' import { largestNesting } from '../../nesting.ts' import { longestBacktickRun } from '../commonmark/backtick-runs.ts' import { nodeAttrs, nodeContent, nodeMarks } from '../../adf/document.ts' @@ -196,7 +196,7 @@ function nodePath(context: InlineContext, index: number): ConvertErrorPath { function carries(node: AdfNode, carried: ReadonlySet, index: number): boolean { if (carried.has(index)) return true - return node.type !== 'text' && inlineNodeNamed(node.type) === undefined + return node.type !== 'text' && inlineNodeModel(node.type) === undefined } function emitLeaf(node: AdfNode, context: InlineContext, index: number): Result { @@ -208,27 +208,27 @@ function emitLeaf(node: AdfNode, context: InlineContext, index: number): Result< } const types = nodeMarks(node).map((mark) => mark.type) if (new Set(types).size !== types.length) return failure('unsupported-node-shape', `a ${node.type} node carries one mark type twice`, path) - const inlineNode = inlineNodeNamed(node.type) - if (inlineNode === undefined) return emitText(node, context, index, path) - if (node.type === 'hardBreak') return emitHardBreak(node, inlineNode, context, index, path) - return emitInlineDirective(node, inlineNode, index, path) + const model = inlineNodeModel(node.type) + if (model === undefined) return emitText(node, context, index, path) + if (node.type === 'hardBreak') return emitHardBreak(node, model, context, index, path) + return emitInlineDirective(node, model, index, path) } -function emitHardBreak(node: AdfNode, inlineNode: InlineNode, context: InlineContext, index: number, path: ConvertErrorPath): Result { +function emitHardBreak(node: AdfNode, model: InlineNodeModel, context: InlineContext, index: number, path: ConvertErrorPath): Result { const empty = refuseContentAndText(node, path) if (!empty.ok) return empty - const attributes = spellInlineNodeAttributes(node, inlineNode) + const attributes = spellInlineNodeAttributes(node, model) if (attributes === undefined) return success({ carry: { first: index, last: index } }) if (attributes === '' && context.spansLines && !context.atBlockEnd) return success({ segments: [syntax('\\\n')] }) return success({ segments: [syntax(spellInlineLeafDirective('hardBreak', attributes))] }) } -function emitInlineDirective(node: AdfNode, inlineNode: InlineNode, index: number, path: ConvertErrorPath): Result { +function emitInlineDirective(node: AdfNode, model: InlineNodeModel, index: number, path: ConvertErrorPath): Result { const empty = refuseContentAndText(node, path) if (!empty.ok) return empty - const attributes = spellInlineNodeAttributes(node, inlineNode) + const attributes = spellInlineNodeAttributes(node, model) if (attributes === undefined) return success({ carry: { first: index, last: index } }) - const slot = inlineNode.textAttribute === undefined ? undefined : nodeAttrs(node)[inlineNode.textAttribute] + const slot = model.textAttribute === undefined ? undefined : nodeAttrs(node)[model.textAttribute] if (slot === undefined) return success({ segments: [syntax(spellInlineLeafDirective(node.type, attributes))] }) if (typeof slot !== 'string') return success({ carry: { first: index, last: index } }) const spans = slotLineEndingFault(node.type, slot) diff --git a/src/markdown/parse/directive-nodes.ts b/src/markdown/parse/directive-nodes.ts index c97cc2e..9211ab5 100644 --- a/src/markdown/parse/directive-nodes.ts +++ b/src/markdown/parse/directive-nodes.ts @@ -1,5 +1,5 @@ import type { AdfAttributes, AdfMark, AdfNode } from '../../adf/document.ts' -import type { BlockNode } from '../../adf/block-nodes.ts' +import type { BlockNodeModel } from '../../adf/block-nodes.ts' import type { ConvertFault } from '../../result.ts' import type { DirectiveAttributes, DirectiveValue } from '../directive-syntax.ts' import type { Elsewhere } from './directive-attributes.ts' @@ -7,17 +7,17 @@ import { attributeNestingMessage, nodeAttrs, nodeContent, nodeMarks } from '../. import { attributeValue, directivePrefix, spellAttributeValue, unknownDirectiveFault } from '../directive-syntax.ts' import { blockArgument } from '../block-directive-arguments.ts' import { blockDirectiveForm } from '../block-directive-forms.ts' -import { blockNodeNamed } from '../../adf/block-nodes.ts' +import { blockNodeModel } from '../../adf/block-nodes.ts' import { carryName } from '../opaque-carry.ts' import { failure, faulted, success, type ConvertErrorPath, type Result } from '../../result.ts' import { inlineMarkSpellingFault } from './directive-marks.ts' -import { inlineNodeNamed } from '../../adf/inline-nodes.ts' +import { inlineNodeModel } from '../../adf/inline-nodes.ts' import { marksAttribute, readMarkValues } from '../block-directive-marks.ts' import { readVocabulary } from './directive-attributes.ts' import { slotLineEndingFault } from '../directive-syntax.ts' import { textDirectiveName } from '../text-directive.ts' -export type BlockDirectiveNode = { contentModel: BlockNode['contentModel']; node: AdfNode } +export type BlockDirectiveNode = { contentModel: BlockNodeModel['contentModel']; node: AdfNode } export function readBlockDirectiveNode( name: string, @@ -28,13 +28,13 @@ export function readBlockDirectiveNode( if (name === carryName) { return failure('malformed-directive', `the name ${carryName} is reserved for the opaque carry, whose block form is the ${carryName} fence`, path) } - const blockNode = blockNodeNamed(name) - if (blockNode === undefined) return faulted(inlineSpellingFault(name) ?? unknownDirectiveFault(name), path) + const model = blockNodeModel(name) + if (model === undefined) return faulted(inlineSpellingFault(name) ?? unknownDirectiveFault(name), path) const argumentKey = blockArgument(name) const rest = new Map(attributes) rest.delete(marksAttribute) const elsewhere: Elsewhere | undefined = argumentKey === undefined ? undefined : { key: argumentKey, slot: 'argument' } - const attrs = readVocabulary(name, rest, blockNode.attributes, elsewhere, path) + const attrs = readVocabulary(name, rest, model.attributes, elsewhere, path) if (!attrs.ok) return attrs if (argument !== undefined) { if (argumentKey === undefined) return failure('unsupported-node-shape', `${name} takes no argument: this one spells one`, path) @@ -43,7 +43,7 @@ export function readBlockDirectiveNode( const spelled = attributes.get(marksAttribute) const marks: Result = spelled === undefined ? success(undefined) : readMarks(name, spelled, path) if (!marks.ok) return marks - return success({ contentModel: blockNode.contentModel, node: namedNode(name, attrs.value, marks.value) }) + return success({ contentModel: model.contentModel, node: namedNode(name, attrs.value, marks.value) }) } export function readInlineDirectiveNode( @@ -52,12 +52,12 @@ export function readInlineDirectiveNode( content: readonly AdfNode[] | undefined, path: ConvertErrorPath, ): Result { - const inlineNode = inlineNodeNamed(name) - if (inlineNode === undefined) return faulted(blockSpellingFault(name) ?? unknownDirectiveFault(name), path) - const slot = inlineNode.textAttribute + const model = inlineNodeModel(name) + if (model === undefined) return faulted(blockSpellingFault(name) ?? unknownDirectiveFault(name), path) + const slot = model.textAttribute if (slot === undefined && content !== undefined) return failure('unsupported-node-shape', `${name} takes no content: this one holds some`, path) const elsewhere: Elsewhere | undefined = slot === undefined ? undefined : { key: slot, slot: 'content' } - const attrs = readVocabulary(name, attributes, inlineNode.attributes, elsewhere, path) + const attrs = readVocabulary(name, attributes, model.attributes, elsewhere, path) if (!attrs.ok) return attrs if (slot !== undefined && content !== undefined) { const text = slotText(content) @@ -75,7 +75,7 @@ export function readInlineDirectiveNode( function inlineSpellingFault(name: string): ConvertFault | undefined { const mark = inlineMarkSpellingFault(name) if (mark !== undefined) return mark - if (inlineNodeNamed(name) === undefined && name !== textDirectiveName) return undefined + if (inlineNodeModel(name) === undefined && name !== textDirectiveName) return undefined return { code: 'unsupported-node-shape', message: `${name} takes the inline form, ${directivePrefix}${name}{…}, never the block form` } } diff --git a/src/markdown/parse/inline-content.ts b/src/markdown/parse/inline-content.ts index ba53f4e..38fa719 100644 --- a/src/markdown/parse/inline-content.ts +++ b/src/markdown/parse/inline-content.ts @@ -8,7 +8,7 @@ import { backtickRun, closingBacktickRun } from '../commonmark/backtick-runs.ts' import { commonMarkLink, linkHref } from '../mark-spellings.ts' import { delimiterFlags, matchEmphasis, runLength } from '../commonmark/emphasis-matching.ts' import { failure, faulted, success, type ConvertErrorPath, type Result } from '../../result.ts' -import { inlineNodeNamed } from '../../adf/inline-nodes.ts' +import { inlineNodeModel } from '../../adf/inline-nodes.ts' import { mergeAdjacentText } from '../../adf/editor-normal.ts' import { noSpans, readInlineDirective } from '../directive-syntax.ts' import { nodeAttrs, nodeMarks } from '../../adf/document.ts' @@ -407,7 +407,7 @@ function imageAlt(inner: readonly Piece[], path: ConvertErrorPath): Result `${scheme}${rest}`), marks }) .map(({ href, marks: held }): AdfNode => ({ marks: [...held.filter((outer) => outer.type !== 'link'), { attrs: { href }, type: 'link' }], text: href, type: 'text' })) -const tableInlineNodes = Object.entries(inlineNodes).map(([type, inlineNode]) => - fc.record({ attrs: attributes(inlineNode.attributes), marks }).map((held): AdfNode => ({ ...held, type })), +const inlineArbitraries = Object.entries(inlineNodes).map(([type, model]) => + fc.record({ attrs: attributes(model.attributes), marks }).map((held): AdfNode => ({ ...held, type })), ) function weighted(arbitraries: readonly Arbitrary[], weight: number): { arbitrary: Arbitrary; weight: number }[] { @@ -112,17 +112,17 @@ const positions = fc.letrec((tie) => { none: fc.constant([]), } const blockMarks = fc.oneof({ arbitrary: fc.constant([]), weight: 4 }, { arbitrary: marks, weight: 1 }) - const tableBlockNodes = Object.entries(blockNodes).map(([type, blockNode]) => { + const blockArbitraries = Object.entries(blockNodes).map(([type, model]) => { const argument = blockArgument(type) - const vocabulary: AttributeVocabulary = argument === undefined ? blockNode.attributes : { ...blockNode.attributes, [argument]: 'string' } - const node = fc.record({ attrs: attributes(vocabulary), content: contentByModel[blockNode.contentModel], marks: blockMarks }).map((held): AdfNode => ({ ...held, type })) - return { leaf: blockNode.contentModel === 'code' || blockNode.contentModel === 'none', node } + const vocabulary: AttributeVocabulary = argument === undefined ? model.attributes : { ...model.attributes, [argument]: 'string' } + const node = fc.record({ attrs: attributes(vocabulary), content: contentByModel[model.contentModel], marks: blockMarks }).map((held): AdfNode => ({ ...held, type })) + return { leaf: model.contentModel === 'code' || model.contentModel === 'none', node } }) const unknownNode = fc .record({ attrs: fc.dictionary(jsonKey, jsonValue, { maxKeys: 2, noNullPrototype: true }), content: fc.array(tie('inline'), { depthIdentifier, maxLength: 2 }), marks, type: unknownType }) .map((held): AdfNode => held) - const leafBlocks = tableBlockNodes.filter((entry) => entry.leaf).map((entry) => entry.node) - const containerBlocks = tableBlockNodes.filter((entry) => !entry.leaf).map((entry) => entry.node) + const leafBlocks = blockArbitraries.filter((entry) => entry.leaf).map((entry) => entry.node) + const containerBlocks = blockArbitraries.filter((entry) => !entry.leaf).map((entry) => entry.node) const misplacedWeight = 7 const paragraph = fc.oneof({ arbitrary: inlineContent, weight: 3 }, { arbitrary: fc.array(backtickRunNode, { maxLength: 4, minLength: 2 }), weight: 1 }).map((content): AdfNode => ({ content, type: 'paragraph' })) const cell = (type: string) => paragraph.map((held): AdfNode => ({ content: [held], type })) @@ -148,7 +148,7 @@ const positions = fc.letrec((tie) => { { depthIdentifier, depthSize: 'small', maxDepth: 4 }, { arbitrary: fc.oneof(...flatBlocks), weight: flatBlocks.reduce((sum, entry) => sum + entry.weight, 0) }, { arbitrary: fc.oneof(...containerBlocks), weight: containerBlocks.length * 2 }, - { arbitrary: fc.oneof(textNode, ...tableInlineNodes, unknownNode), weight: misplacedWeight }, + { arbitrary: fc.oneof(textNode, ...inlineArbitraries, unknownNode), weight: misplacedWeight }, { arbitrary: fc.oneof(...nestingCommonMarkShapes), weight: nestingCommonMarkShapes.length * nestingCommonMarkShapeWeight }, ), inline: fc.oneof( @@ -156,8 +156,8 @@ const positions = fc.letrec((tie) => { { arbitrary: textNode, weight: 12 }, { arbitrary: autolinkTextNode, weight: 2 }, { arbitrary: backtickRunNode, weight: 3 }, - { arbitrary: fc.oneof(...tableInlineNodes), weight: 7 }, - { arbitrary: fc.oneof(...tableBlockNodes.map((entry) => entry.node), unknownNode), weight: 2 }, + { arbitrary: fc.oneof(...inlineArbitraries), weight: 7 }, + { arbitrary: fc.oneof(...blockArbitraries.map((entry) => entry.node), unknownNode), weight: 2 }, ), } }) diff --git a/todo-history.md b/todo-history.md index 6b330a1..9d0c615 100644 --- a/todo-history.md +++ b/todo-history.md @@ -1000,12 +1000,15 @@ The done `todo.md` items in full, as they were written. `todo.md` keeps a one-li to know a format. Rename to the noun `spec/flavour.md` uses, types and accessors with them. Before 7 doubles the import sites. **Done** (2026-09-21): the tables are `adf/block-nodes.ts` and `adf/inline-nodes.ts`, - `blockNodes` and `inlineNodes` holding `BlockNode` and `InlineNode`, read by - `blockNodeNamed` and `inlineNodeNamed` — the accessor named apart from the entry so every - call site's local is the one name `blockNode`/`inlineNode` rather than shadowing its own - lookup. `BlockType` stays: it names a node type, the parallel of `mark-attributes.ts`'s - `MarkType`. `markdown/`'s `blockDirectiveForm`, `blockArgument` and the `spell*Directive*` - family keep the word, naming the spelling rather than the node. + `blockNodes` and `inlineNodes` — `spec/flavour.md`'s own headings — each row a + `BlockNodeModel` or `InlineNodeModel` read by `blockNodeModel` and `inlineNodeModel`. The row + is the node's model, never the node: `BlockNode` beside `AdfNode` put two kinds of thing one + lookup apart in every signature the rename touched, where §8 already calls the content model + the model. `markdown-to-adf.ts`'s own `blockNodes`/`blockNode` walk became + `readBlocks`/`readBlock`, so the table's name means one thing repo-wide. `BlockType` stays: + it names a node type, the parallel of `mark-attributes.ts`'s `MarkType`. `markdown/`'s + `blockDirectiveForm`, `blockArgument` and the `spell*Directive*` family keep the word, + naming the spelling rather than the node. ## 5 — Ship `0.1.0` diff --git a/todo.md b/todo.md index 36c7a69..e60fea0 100644 --- a/todo.md +++ b/todo.md @@ -22,7 +22,7 @@ Start a session with: `Read AGENTS.md and todo.md, then do what todo.md's "Next ## Milestones Shipping order: 3h, 3i, 3j, 5a, 5b, 5c, 5d, 5 → `0.1.0` (shipped 2026-09-05); 3k, 11, 4, 12, 13, 4b, -4c, 14, 15, 16, 18, 4d, 28, 17, 29, 19, 20, 21, 22, 23, 24, 25, 30, 26, 27, 10, 6, 7, 31, 5f, 5g → +4c, 14, 15, 16, 18, 4d, 28, 17, 29, 19, 20, 21, 22, 32, 23, 24, 25, 30, 26, 27, 10, 6, 7, 31, 5f, 5g → `0.2.0`; 8, 9 → TBD; 5e last. The numbering is the order the work was planned in, not the order it ships. Everything known and @@ -44,7 +44,8 @@ panel says the next reader pays for. 29 and 30 come from 17's prose pass (2026-09-20). 29 reads first because every goal is what a later ask is settled against, 19's included; 30 sits beside 25, the other chunk rereading AGENTS.md. 31 comes from 20's gate runs (2026-09-21) and reads beside 5f, the other chunk putting a measured -number under the pipeline. +number under the pipeline. 32 comes from 21's review (2026-09-21) and reads beside 22, the other +chunk clearing a §11 seam. - [ ] **31 — The branch figure the floor is read against is stable (`0.2.0`).** Three Node test legs over one unchanged tree reported `emit/inline-line.ts` at 95.83%, 96.23% and 96.23%, @@ -59,6 +60,14 @@ number under the pipeline. `parse/` → `emit/` imports fetch this type from `emit/line-escaping.ts`, camouflaging the two that are the deliberate spelling consultation. Move it, and name those two in §11 as the whole of that surface, so a reviewer checks the seam with one grep. +- [ ] **32 — The mark depth `adf/` counts is stated in ADF's terms (`0.2.0`).** + `document.ts`'s `markAttributeNesting` is `largestNesting - 3`, and both the comment above it + and AGENTS.md §8 give the reason as markdown's: the block directive spells the whole mark set + as one JSON attribute, so the parser reads the value at the bottom of array, mark and + `attrs`. That is a format's spelling deciding a constant inside the directory §11 forbids to + know a format. Move the derivation to where that spelling lives, or state the three levels in + ADF's own vocabulary. Before 7 gives the constant a second format whose spelling may not + spend the same three levels. - [ ] **23 — The block-directive fragments are one file (`0.2.0`).** `block-directive-arguments.ts`, `-forms.ts` and `-marks.ts` are three files under 25 lines answering one question. Fold them, and take `src/markdown/` — the worst level both architects named, 13 entries with no