13 lines
668 B
TypeScript
13 lines
668 B
TypeScript
import type { JsonValue } from '../json-value.ts'
|
|
import { carryFencePrefix } from './opaque-carry.ts'
|
|
import { infoStringCarries } from './commonmark/grammar.ts'
|
|
|
|
export type LanguageSlot = { info: string; kind: 'fence' } | { kind: 'attribute' } | { kind: 'none' }
|
|
|
|
// 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' }
|
|
return { info: language, kind: 'fence' }
|
|
}
|