From 2d696c58d5379d794b084c968a1b46ed7419020b Mon Sep 17 00:00:00 2001 From: xnought Date: Mon, 27 Nov 2023 22:36:55 -0800 Subject: [PATCH] feat: replace cite with link --- frontend/src/lib/Markdown.svelte | 16 +++++++++++++++- frontend/src/lib/References.svelte | 6 +++--- frontend/src/routes/upload/+page.svelte | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/frontend/src/lib/Markdown.svelte b/frontend/src/lib/Markdown.svelte index d2bdeae0..92929eda 100644 --- a/frontend/src/lib/Markdown.svelte +++ b/frontend/src/lib/Markdown.svelte @@ -4,7 +4,21 @@ export let text = ``; // they recommend also sanitizing input text https://github.com/cure53/DOMPurify - $: mdToHTML = marked(text); + + $: mdToHTML = marked(replaceCite(text)); + + /** + * @todo this is a hacky way to do this, but it works for now + * Instead use the builtin extensions https://marked.js.org/using_pro#extensions + */ + function replaceCite(str: string) { + // replace \cite{} with [1] + const newStr = str.replaceAll(/\\cite{(.+?)}/g, (match, p1) => { + console.log(match, p1); + return `[${p1}]`; + }); + return newStr; + } {@html mdToHTML} diff --git a/frontend/src/lib/References.svelte b/frontend/src/lib/References.svelte index f4907f9b..2b1c80cb 100644 --- a/frontend/src/lib/References.svelte +++ b/frontend/src/lib/References.svelte @@ -34,9 +34,9 @@ {#if bib} {#each bib.entries_raw as entry, i} -
-
- [{i + 1}] +
+
+ [{entry._id}]
diff --git a/frontend/src/routes/upload/+page.svelte b/frontend/src/routes/upload/+page.svelte index 40695a5e..f5cc2084 100644 --- a/frontend/src/routes/upload/+page.svelte +++ b/frontend/src/routes/upload/+page.svelte @@ -61,7 +61,7 @@