From 3b1b6685f2a9935b79bfdc476822a3526882754b Mon Sep 17 00:00:00 2001 From: Nils Pukropp Date: Fri, 27 Mar 2026 15:16:12 +0100 Subject: [PATCH] fixed regex --- frontend/src/pages/posts/[slug].astro | 29 +++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/frontend/src/pages/posts/[slug].astro b/frontend/src/pages/posts/[slug].astro index da4c595..9c198db 100644 --- a/frontend/src/pages/posts/[slug].astro +++ b/frontend/src/pages/posts/[slug].astro @@ -14,19 +14,36 @@ let post: PostDetail | null = null; let html = ''; let error = ''; -// Custom citation pre-processor +// Custom citation pre-processor (Regex-Free!) function processCitations(text: string) { - // Using RegExp constructor to completely bypass Astro/esbuild literal parsing bugs - const citeRegex = new RegExp('\\', 'g'); + let result = text; - return text.replace(citeRegex, (match, citations) => { + // Keep looking for citation tags until there are none left + while (result.includes('', startIndex)) { + + // Safety check: if there's no closing bracket, stop to prevent infinite loops + if (endIndex === -1) break; + + // Extract the exact string to replace (e.g., "") + const fullMatch = result.substring(startIndex, endIndex + 1); + + // Extract just the numbers/IDs (e.g., "1, 2") + const citations = result.substring(startIndex + 6, endIndex).trim(); + + // Build the HTML links const links = citations.split(',').map((c: string) => { const id = c.trim(); return `${id}`; }).join(', '); - return `[${links}]`; - }); + // Build the superscript wrapper + const replacement = `[${links}]`; + + // Replace the first occurrence we found, then the loop will handle the rest + result = result.replace(fullMatch, replacement); + } + + return result; } try {