From c3bc2eb5728552614651f9c42731d40c2384634f Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 3 Oct 2026 14:45:48 +0200 Subject: [PATCH] Read a carry fence's type in one function --- src/markdown/code-language.ts | 4 ++-- src/markdown/opaque-carry.ts | 5 +++++ src/markdown/parse/markdown-to-adf.ts | 7 ++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/markdown/code-language.ts b/src/markdown/code-language.ts index 75ddf83..846b64e 100644 --- a/src/markdown/code-language.ts +++ b/src/markdown/code-language.ts @@ -1,5 +1,5 @@ import type { JsonValue } from '../json-value.ts' -import { carryFencePrefix } from './opaque-carry.ts' +import { carryFenceType } from './opaque-carry.ts' import { infoStringCarries } from './commonmark/grammar.ts' export type LanguageSlot = { info: string; kind: 'fence' } | { kind: 'attribute' } | { kind: 'none' } @@ -7,6 +7,6 @@ export type LanguageSlot = { info: string; kind: 'fence' } | { kind: 'attribute' // spec/flavour.md, The CommonMark blocks: the one slot a codeBlock's language rides. export function languageSlot(language: JsonValue | undefined): LanguageSlot { if (language === undefined) return { kind: 'none' } - if (typeof language !== 'string' || language.startsWith(carryFencePrefix) || !infoStringCarries(language)) return { kind: 'attribute' } + if (typeof language !== 'string' || carryFenceType(language) !== undefined || !infoStringCarries(language)) return { kind: 'attribute' } return { info: language, kind: 'fence' } } diff --git a/src/markdown/opaque-carry.ts b/src/markdown/opaque-carry.ts index f15960f..90bd538 100644 --- a/src/markdown/opaque-carry.ts +++ b/src/markdown/opaque-carry.ts @@ -32,6 +32,11 @@ export function carriedInline(node: AdfNode, path: ConvertErrorPath): Result { if (type !== '' && !infoStringCarries(type)) { return { fault: unsupportedNodeShape(`the carry fence names a type no info string carries back: spell it ${carryFencePrefix} with the type in the JSON`) } diff --git a/src/markdown/parse/markdown-to-adf.ts b/src/markdown/parse/markdown-to-adf.ts index 40a0742..161fdfb 100644 --- a/src/markdown/parse/markdown-to-adf.ts +++ b/src/markdown/parse/markdown-to-adf.ts @@ -5,7 +5,7 @@ import type { ConvertFault } from '../../result.ts' import type { Flavour } from '../plain-conventions.ts' import type { LineContainer } from '../line-container.ts' import type { LinkDefinitions } from './inline-content.ts' -import { carryFencePrefix, readCarriedBlock } from '../opaque-carry.ts' +import { carryFenceType, readCarriedBlock } from '../opaque-carry.ts' import { commonMarkSpelling, type SpellingMemo } from '../emit/adf-to-markdown.ts' import { documentAttribute, documentName, documentSpelling, listBreakName, listBreakSpelling } from '../block-directive.ts' import { failure, faulted, positioned, success, type ConvertErrorPath, type ParseError, type Result, type SourcePosition } from '../../result.ts' @@ -303,8 +303,9 @@ function listNode(node: AdfNode, items: readonly Block[][], reading: Reading, pa } function codeBlockNode(language: string, text: string, reading: Reading, path: ConvertErrorPath, depth: number): Result { - if (language.startsWith(carryFencePrefix)) { - const carried = readCarriedBlock(language.slice(carryFencePrefix.length), text, depth) + const carriedType = carryFenceType(language) + if (carriedType !== undefined) { + const carried = readCarriedBlock(carriedType, text, depth) if (carried.fault !== undefined) return faulted(carried.fault, path) reading.carried.add(carried.value) return success(carried.value)