fix(text): handle fenced code fence termination

This commit is contained in:
Peter Steinberger
2026-03-28 08:32:18 +00:00
parent c0a56ac1a1
commit a735a1a2d4

View File

@@ -6,7 +6,7 @@ export interface CodeRegion {
export function findCodeRegions(text: string): CodeRegion[] {
const regions: CodeRegion[] = [];
const fencedRe = /(^|\n)(```|~~~)[^\n]*\n[\s\S]*?(?:\n\2(?:\n|$)|$)/g;
const fencedRe = /(^|\n)(```|~~~)[^\n]*\n[\s\S]*?(?:\n\2|$)/g;
for (const match of text.matchAll(fencedRe)) {
const start = (match.index ?? 0) + match[1].length;
regions.push({ start, end: start + match[0].length - match[1].length });