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 {