fixed regex
This commit is contained in:
@@ -14,19 +14,36 @@ let post: PostDetail | null = null;
|
|||||||
let html = '';
|
let html = '';
|
||||||
let error = '';
|
let error = '';
|
||||||
|
|
||||||
// Custom citation pre-processor
|
// Custom citation pre-processor (Regex-Free!)
|
||||||
function processCitations(text: string) {
|
function processCitations(text: string) {
|
||||||
// Using RegExp constructor to completely bypass Astro/esbuild literal parsing bugs
|
let result = text;
|
||||||
const citeRegex = new RegExp('\\', 'g');
|
|
||||||
|
|
||||||
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 links = citations.split(',').map((c: string) => {
|
||||||
const id = c.trim();
|
const id = c.trim();
|
||||||
return `<a href="#cite-${id}" class="text-sapphire hover:text-sky transition-colors no-underline">${id}</a>`;
|
return `<a href="#cite-${id}" class="text-sapphire hover:text-sky transition-colors no-underline">${id}</a>`;
|
||||||
}).join(', ');
|
}).join(', ');
|
||||||
|
|
||||||
return `<sup class="bg-surface0 px-1.5 py-0.5 rounded-md border border-surface1 ml-0.5 font-mono text-[10px] md:text-xs shadow-sm align-super">[${links}]</sup>`;
|
// Build the superscript wrapper
|
||||||
});
|
const replacement = `<sup class="bg-surface0 px-1.5 py-0.5 rounded-md border border-surface1 ml-0.5 font-mono text-[10px] md:text-xs shadow-sm align-super">[${links}]</sup>`;
|
||||||
|
|
||||||
|
// Replace the first occurrence we found, then the loop will handle the rest
|
||||||
|
result = result.replace(fullMatch, replacement);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user