added citations
This commit is contained in:
@@ -14,12 +14,30 @@ let post: PostDetail | null = null;
|
||||
let html = '';
|
||||
let error = '';
|
||||
|
||||
// Custom citation pre-processor
|
||||
function processCitations(text: string) {
|
||||
// Using RegExp constructor to completely bypass Astro/esbuild literal parsing bugs
|
||||
const citeRegex = new RegExp('\\', 'g');
|
||||
|
||||
return text.replace(citeRegex, (match, citations) => {
|
||||
const links = citations.split(',').map((c: string) => {
|
||||
const id = c.trim();
|
||||
return `<a href="#cite-${id}" class="text-sapphire hover:text-sky transition-colors no-underline">${id}</a>`;
|
||||
}).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>`;
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`${API_URL}/api/posts/${slug}`);
|
||||
if (response.ok) {
|
||||
post = await response.json();
|
||||
if (post) {
|
||||
html = await marked.parse(post.content);
|
||||
// 1. Process citations first
|
||||
const processedContent = processCitations(post.content);
|
||||
// 2. Then parse the rest of the markdown
|
||||
html = await marked.parse(processedContent);
|
||||
}
|
||||
} else {
|
||||
error = 'Post not found';
|
||||
@@ -76,12 +94,10 @@ function formatSlug(slug: string) {
|
||||
)}
|
||||
</article>
|
||||
|
||||
<!-- KaTeX for LaTeX Math Rendering -->
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.10/dist/katex.min.css" crossorigin="anonymous">
|
||||
<script is:inline src="https://cdn.jsdelivr.net/npm/katex@0.16.10/dist/katex.min.js" crossorigin="anonymous"></script>
|
||||
<script is:inline src="https://cdn.jsdelivr.net/npm/katex@0.16.10/dist/contrib/auto-render.min.js" crossorigin="anonymous"></script>
|
||||
|
||||
<!-- Highlight.js for Code Blocks -->
|
||||
<script is:inline src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
|
||||
|
||||
<script>
|
||||
|
||||
Reference in New Issue
Block a user