Read the inline text, and decode the escapes and references CommonMark spells (#33)
CI / gate (push) Successful in 4s

This commit was merged in pull request #33.
This commit is contained in:
2026-08-30 23:32:57 +02:00
parent ddc55bc7c8
commit 0476d33b7b
25 changed files with 729 additions and 110 deletions
+17
View File
@@ -1,3 +1,20 @@
export function backtickRun(text: string, index: number): number {
let length = 0
while (text.charAt(index + length) === '`') length += 1
return length
}
// Where the run of exactly `opener` backticks closing a code span begins, `undefined` where none does.
export function closingBacktickRun(text: string, from: number, opener: number): number | undefined {
let cursor = from
while (cursor < text.length) {
const run = backtickRun(text, cursor)
if (run === opener) return cursor
cursor += run === 0 ? 1 : run
}
return undefined
}
export function fencedCodeBlock(info: string, body: string): string {
const fence = '`'.repeat(Math.max(3, longestBacktickRun(body) + 1))
return body === '' ? `${fence}${info}\n${fence}` : `${fence}${info}\n${body}\n${fence}`