|
@@ -1,6 +1,8 @@
|
|
<script lang="ts">
|
|
<script lang="ts">
|
|
import hljs from 'highlight.js';
|
|
import hljs from 'highlight.js';
|
|
import { loadPyodide } from 'pyodide';
|
|
import { loadPyodide } from 'pyodide';
|
|
|
|
+ import mermaid from 'mermaid';
|
|
|
|
+
|
|
import { getContext, getAllContexts } from 'svelte';
|
|
import { getContext, getAllContexts } from 'svelte';
|
|
import { copyToClipboard } from '$lib/utils';
|
|
import { copyToClipboard } from '$lib/utils';
|
|
|
|
|
|
@@ -12,6 +14,7 @@
|
|
|
|
|
|
export let id = '';
|
|
export let id = '';
|
|
|
|
|
|
|
|
+ export let token;
|
|
export let lang = '';
|
|
export let lang = '';
|
|
export let code = '';
|
|
export let code = '';
|
|
|
|
|
|
@@ -207,23 +210,39 @@ __builtins__.input = input`);
|
|
};
|
|
};
|
|
|
|
|
|
let debounceTimeout;
|
|
let debounceTimeout;
|
|
- $: if (code) {
|
|
|
|
- // Function to perform the code highlighting
|
|
|
|
- const highlightCode = () => {
|
|
|
|
- highlightedCode = hljs.highlightAuto(code, hljs.getLanguage(lang)?.aliases).value || code;
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- // Clear the previous timeout if it exists
|
|
|
|
- clearTimeout(debounceTimeout);
|
|
|
|
|
|
|
|
- // Set a new timeout to debounce the code highlighting
|
|
|
|
- debounceTimeout = setTimeout(highlightCode, 10);
|
|
|
|
|
|
+ $: if (code) {
|
|
|
|
+ if (lang === 'mermaid' && (token?.raw ?? '').endsWith('```')) {
|
|
|
|
+ // Function to perform the code highlighting
|
|
|
|
+ const renderMermaid = async () => {
|
|
|
|
+ // mermaid.initialize({ startOnLoad: true });
|
|
|
|
+ await mermaid.run({
|
|
|
|
+ querySelector: `.mermaid-${id}`
|
|
|
|
+ });
|
|
|
|
+ };
|
|
|
|
+ // Clear the previous timeout if it exists
|
|
|
|
+ clearTimeout(debounceTimeout);
|
|
|
|
+ // Set a new timeout to debounce the code highlighting
|
|
|
|
+ debounceTimeout = setTimeout(renderMermaid, 50);
|
|
|
|
+ } else {
|
|
|
|
+ // Function to perform the code highlighting
|
|
|
|
+ const highlightCode = () => {
|
|
|
|
+ highlightedCode = hljs.highlightAuto(code, hljs.getLanguage(lang)?.aliases).value || code;
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ // Clear the previous timeout if it exists
|
|
|
|
+ clearTimeout(debounceTimeout);
|
|
|
|
+ // Set a new timeout to debounce the code highlighting
|
|
|
|
+ debounceTimeout = setTimeout(highlightCode, 10);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
</script>
|
|
</script>
|
|
|
|
|
|
<div class="my-2" dir="ltr">
|
|
<div class="my-2" dir="ltr">
|
|
{#if lang === 'mermaid'}
|
|
{#if lang === 'mermaid'}
|
|
- <pre class="mermaid">{code}</pre>
|
|
|
|
|
|
+ {#key code}
|
|
|
|
+ <pre class="mermaid-{id}">{code}</pre>
|
|
|
|
+ {/key}
|
|
{:else}
|
|
{:else}
|
|
<div
|
|
<div
|
|
class="flex justify-between bg-[#202123] text-white text-xs px-4 pt-1 pb-0.5 rounded-t-lg overflow-x-auto"
|
|
class="flex justify-between bg-[#202123] text-white text-xs px-4 pt-1 pb-0.5 rounded-t-lg overflow-x-auto"
|