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

Answer architecture round 2: every builder joins its pieces through one bounded join, the readers take the engine guard, every refusal stands at the document's path, and a portable list's refusal names its own place

This commit is contained in:
2026-10-12 17:42:24 +02:00
committed by Lillem4n
parent 2b5d22cbc6
commit 3414c8690a
25 changed files with 379 additions and 249 deletions
+10 -5
View File
@@ -16,16 +16,21 @@ export function closingBacktickRun(text: string, from: number, opener: number):
}
export function fencedCodeBlock(info: string, body: string): string {
return fencePieces(info, body).join('')
}
export function fencePieces(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}`
return body === '' ? [fence, info, '\n', fence] : [fence, info, '\n', body, '\n', fence]
}
export function longestBacktickRun(text: string): number {
let longest = 0
let current = 0
for (const character of text) {
current = character === '`' ? current + 1 : 0
longest = Math.max(longest, current)
for (let start = text.indexOf('`'); start !== -1; ) {
let end = start + 1
while (text.charAt(end) === '`') end += 1
longest = Math.max(longest, end - start)
start = text.indexOf('`', end)
}
return longest
}