Skip to content

Commit

Permalink
feat: replace cite with link
Browse files Browse the repository at this point in the history
  • Loading branch information
xnought committed Nov 28, 2023
1 parent 542a8bb commit 2d696c5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
16 changes: 15 additions & 1 deletion frontend/src/lib/Markdown.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="#ref-1">[1]</a>
const newStr = str.replaceAll(/\\cite{(.+?)}/g, (match, p1) => {
console.log(match, p1);
return `[<a href="#${p1}">${p1}</a>]`;
});
return newStr;
}
</script>

{@html mdToHTML}
6 changes: 3 additions & 3 deletions frontend/src/lib/References.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@

{#if bib}
{#each bib.entries_raw as entry, i}
<div class="flex gap-2 mt-2">
<div class="w-5">
[{i + 1}]
<div class="mt-2" id={`#${entry._id}`}>
<div style="font-size: 12px;">
[{entry._id}]
</div>
<div>
<div style="font-size: 17px;">
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/routes/upload/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

<Card
class="max-w-full"
style="height: 600px; overflow-y: scroll; padding: 0;"
style="height: 600px; overflow-y: scroll; padding: 0; padding-top: 4px; padding-left: 4px;"
>
<Tabs contentClass="bg-none p-5" style="underline">
<TabItem title="article content" open>
Expand Down

0 comments on commit 2d696c5

Please sign in to comment.