3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-21 15:42:58 +01:00

Answer architecture round 1: the comments the panel found as bare spec pointers state their rule, and the spec cites no plan item

This commit is contained in:
2026-10-04 22:55:08 +02:00
committed by Lillem4n
parent 35b37de47f
commit 88ec96556c
5 changed files with 7 additions and 6 deletions
+1 -1
View File
@@ -196,7 +196,7 @@ is the fence.
CommonMark input may contain raw HTML. `markdownToAdf` routes each construct through the foreign CommonMark input may contain raw HTML. `markdownToAdf` routes each construct through the foreign
HTML element mapping (`docs/decisions.md` §Foreign HTML sorts three ways; specified with the HTML HTML element mapping (`docs/decisions.md` §Foreign HTML sorts three ways; specified with the HTML
dialect, `todo.md` item 6) — ADF has no raw-HTML node, so a construct without a mapping, comments dialect) — ADF has no raw-HTML node, so a construct without a mapping, comments
and processing instructions included, is an error result naming it. The flavour never emits raw and processing instructions included, is an error result naming it. The flavour never emits raw
HTML. HTML.
+1 -1
View File
@@ -40,7 +40,7 @@ const bareToken = new RegExp(`^${bareTokenSource}$`)
const directiveName = /[a-z][A-Za-z0-9]*/y const directiveName = /[a-z][A-Za-z0-9]*/y
const inlineDirectiveOpener = new RegExp(`${directivePrefix}[a-z][A-Za-z0-9]*[[{]`, 'y') const inlineDirectiveOpener = new RegExp(`${directivePrefix}[a-z][A-Za-z0-9]*[[{]`, 'y')
const lineEnd = /^[ \t]*$/ const lineEnd = /^[ \t]*$/
// spec/flavour.md, Attributes. // A quoted value spells these as \uXXXX: CommonMark binds a code span, entity, HTML tag or pipe cell before a directive.
const reservedSource = '[&<`|]' const reservedSource = '[&<`|]'
const quotedEscapes = new RegExp(reservedSource, 'g') const quotedEscapes = new RegExp(reservedSource, 'g')
const rawReserved = new RegExp(reservedSource) const rawReserved = new RegExp(reservedSource)
+1 -1
View File
@@ -47,7 +47,7 @@ export function writeMarkdown(document: AdfDocument, flavour: Flavour): Result<s
return success(text === '' ? '' : `${text}\n`) return success(text === '' ? '' : `${text}\n`)
} }
// headroom: the least slack any depth guard below the walk has. // headroom: the nesting levels the deepest node below may still spend before the 500-level guard refuses it.
function walkBlocks(nodes: readonly AdfNode[], path: ConvertErrorPath, depth: number, writing: Writing): Result<PlacedBlocks> { function walkBlocks(nodes: readonly AdfNode[], path: ConvertErrorPath, depth: number, writing: Writing): Result<PlacedBlocks> {
let headroom = largestNesting - depth let headroom = largestNesting - depth
if (headroom < 0) return tooDeep(path) if (headroom < 0) return tooDeep(path)
+3 -3
View File
@@ -130,7 +130,7 @@ function lineVerdict(segments: readonly InlineSegment[], container: LineContaine
return run === undefined ? { kind: 'line', text: assembled.line } : { kind: 'unspellable-run', runs: [run, ...others] } return run === undefined ? { kind: 'line', text: assembled.line } : { kind: 'unspellable-run', runs: [run, ...others] }
} }
// spec/flavour.md, Inline nodes. // A space or tab CommonMark strips at a line edge rides !adf:text{} instead.
function spellEdgeWhitespace(segments: readonly InlineSegment[]): InlineSegment[] { function spellEdgeWhitespace(segments: readonly InlineSegment[]): InlineSegment[] {
const spelled: InlineSegment[] = [] const spelled: InlineSegment[] = []
for (const [index, segment] of segments.entries()) { for (const [index, segment] of segments.entries()) {
@@ -194,7 +194,7 @@ function inlineRuns(nodes: readonly AdfNode[], depth: number, firstIndex: number
const runs: InlineRun[] = [] const runs: InlineRun[] = []
for (const [offset, node] of nodes.entries()) { for (const [offset, node] of nodes.entries()) {
const index = firstIndex + offset const index = firstIndex + offset
// spec/flavour.md, Marks. // `depth` indexes each node's marks, outermost first; a carried node spells its marks inside the carry.
const mark = carries(node, carried, index) ? undefined : nodeMarks(node)[depth] const mark = carries(node, carried, index) ? undefined : nodeMarks(node)[depth]
if (mark === undefined) { if (mark === undefined) {
runs.push({ index, kind: 'plain', node }) runs.push({ index, kind: 'plain', node })
@@ -263,7 +263,7 @@ function emitInlineDirective(node: AdfNode, model: InlineNodeModel, index: numbe
return success({ segments: [syntax(spellInlineDirectiveOpener(node.type)), ...content, syntax(`]${attributes}`)] }) return success({ segments: [syntax(spellInlineDirectiveOpener(node.type)), ...content, syntax(`]${attributes}`)] })
} }
// spec/flavour.md, Text CommonMark cannot hold plainly. // CommonMark reads a raw carriage return as a line ending and a null character as U+FFFD, so neither is written raw.
function emitText(node: AdfNode, context: InlineContext, index: number): Emission { function emitText(node: AdfNode, context: InlineContext, index: number): Emission {
if (!isBareText(node) || typeof node.text !== 'string' || node.text === '') return { carry: { first: index, last: index } } if (!isBareText(node) || typeof node.text !== 'string' || node.text === '') return { carry: { first: index, last: index } }
const escaping: InlineEscaping = context.bracketed ? 'bracketed' : 'backslash' const escaping: InlineEscaping = context.bracketed ? 'bracketed' : 'backslash'
+1
View File
@@ -15,6 +15,7 @@ export type InlineEscaping = 'backslash' | 'bracketed' | 'bracketed-link-target'
export type NodeRange = { first: number; last: number } export type NodeRange = { first: number; last: number }
// `depth` is the index into each node's marks array that the run spells.
export type MarkRun = NodeRange & { depth: number } export type MarkRun = NodeRange & { depth: number }
export type InlineSegment = export type InlineSegment =