3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-19 06:35:44 +01:00

Answer architecture round 3: the forecast never overcounts, the carry's JSON and the portable code block join through joinedWithin, and the list's choice of form stands in its own function

This commit is contained in:
2026-10-12 17:52:15 +02:00
committed by Lillem4n
parent 3414c8690a
commit ae1a47f1bc
14 changed files with 83 additions and 84 deletions
+1 -1
View File
@@ -457,7 +457,7 @@ test('refuses compact JSON in the carry fence without building its two-space spe
})
test('refuses a directive whose CommonMark spelling would pass V8\'s longest string', () => {
const markdown = `!adf:blockquote\n${'- '.repeat(490)}a\\\n${'b\\\n'.repeat(560_000)}c\n!adf:/blockquote\n`
const markdown = `!adf:blockquote\n${'>'.repeat(490)} a\\\n${'b\\\n'.repeat(560_000)}c\n!adf:/blockquote\n`
assert.equal(content(losslessMarkdownToAdf(markdown)), 'unsupported-node-shape: spelled as markdown, this would be longer than 536870888 characters, the longest string V8 holds')
})
+4 -3
View File
@@ -51,8 +51,9 @@ function readDocument(markdown: string, claims: Claims): Result<AdfDocument, Par
)
}
function readMarkdown(markdown: string, claims: Claims): Result<AdfDocument, ParseError> {
if (typeof markdown !== 'string') return positioned(failure('not-a-string', `markdown is a string: found ${typeName(markdown)}`, []), { line: 1, offset: 0 })
// A failure naming no position stands at the start of the input, which readDocument gives it.
function readMarkdown(markdown: string, claims: Claims): Result<AdfDocument> {
if (typeof markdown !== 'string') return failure('not-a-string', `markdown is a string: found ${typeName(markdown)}`, [])
const parsed = parseBlocks(markdown, claims)
const [only] = parsed.blocks
if (parsed.blocks.length === 1 && only?.kind === 'directive' && only.name === documentName) {
@@ -60,7 +61,7 @@ function readMarkdown(markdown: string, claims: Claims): Result<AdfDocument, Par
return fault === undefined ? success({ type: 'doc', version: 1 }) : positioned(faulted(fault, []), only.position)
}
const reading: Reading = { claims, definitions: parsed.definitions, inExpand: false, memo: new Map() }
const content = positioned(readBlocks(parsed.blocks, reading, [], 0), { line: 1, offset: 0 })
const content = readBlocks(parsed.blocks, reading, [], 0)
if (!content.ok) return content
const document: AdfDocument = { content: content.value, type: 'doc', version: 1 }
if (claims.taskMarkers) mintTaskIds(document, markdown)