Emitter 2d: the opaque carry in both positions and the reserved info string
CI / gate (push) Successful in 4s

This commit is contained in:
2026-08-26 15:46:02 +02:00
parent 038473ee73
commit 6f674b99b3
14 changed files with 271 additions and 20 deletions
+30
View File
@@ -0,0 +1,30 @@
import type { AdfNode } from './adf-document.ts'
import type { JsonSpelling } from './canonical-json.ts'
import { failure, success, type ConvertErrorPath, type Result } from './result.ts'
import { isJsonValue } from './json-value.ts'
import { largestNesting } from './nesting.ts'
import { longestBacktickRun } from './backtick-runs.ts'
import { serializeCanonicalJson } from './canonical-json.ts'
import { spellAttributes, spellStringAttribute } from './directive-attributes.ts'
export const carryName = 'adf'
export function carriedBlock(node: AdfNode, path: ConvertErrorPath): Result<string> {
const json = carriedJson(node, 'two-space', path)
if (!json.ok) return json
const fence = '`'.repeat(Math.max(3, longestBacktickRun(json.value) + 1))
return success(`${fence}${carryName}\n${json.value}\n${fence}`)
}
export function carriedInline(node: AdfNode, path: ConvertErrorPath): Result<string> {
const json = carriedJson(node, 'compact', path)
if (!json.ok) return json
return success(`:${carryName}${spellAttributes([['json', spellStringAttribute(json.value)]])}`)
}
function carriedJson(node: AdfNode, spelling: JsonSpelling, path: ConvertErrorPath): Result<string> {
if (!isJsonValue(node)) {
return failure('unsupported-node-shape', `a carried node nests deeper than the ${largestNesting} levels the emitter carries`, path)
}
return success(serializeCanonicalJson(node, spelling))
}