mirror of
https://github.com/open-webui/open-webui
synced 2025-01-19 09:16:44 +00:00
fix: mermaid rendering issue
This commit is contained in:
parent
1329eea5e5
commit
b31de299e4
@ -213,15 +213,21 @@ __builtins__.input = input`);
|
||||
|
||||
let debounceTimeout;
|
||||
|
||||
$: if (code) {
|
||||
if (lang === 'mermaid' && (token?.raw ?? '').endsWith('```')) {
|
||||
(async () => {
|
||||
const drawMermaidDiagram = async () => {
|
||||
try {
|
||||
const { svg } = await mermaid.render(`mermaid-${id}`, code);
|
||||
mermaidHtml = svg;
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
}
|
||||
};
|
||||
|
||||
$: if (code) {
|
||||
if (lang === 'mermaid' && (token?.raw ?? '').endsWith('```')) {
|
||||
(async () => {
|
||||
if (!mermaidHtml) {
|
||||
await drawMermaidDiagram();
|
||||
}
|
||||
})();
|
||||
} else {
|
||||
// Function to perform the code highlighting
|
||||
@ -235,19 +241,6 @@ __builtins__.input = input`);
|
||||
debounceTimeout = setTimeout(highlightCode, 10);
|
||||
}
|
||||
}
|
||||
|
||||
onMount(async () => {
|
||||
await mermaid.initialize({ startOnLoad: true });
|
||||
|
||||
if (lang === 'mermaid' && (token?.raw ?? '').endsWith('```')) {
|
||||
try {
|
||||
const { svg } = await mermaid.render(`mermaid-${id}`, code);
|
||||
mermaidHtml = svg;
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="my-2" dir="ltr">
|
||||
@ -255,7 +248,7 @@ __builtins__.input = input`);
|
||||
{#if mermaidHtml}
|
||||
{@html mermaidHtml}
|
||||
{:else}
|
||||
<pre class=" mermaid-{id}">{code}</pre>
|
||||
<pre class="mermaid">{code}</pre>
|
||||
{/if}
|
||||
{:else}
|
||||
<div
|
||||
|
@ -180,7 +180,6 @@
|
||||
await tick();
|
||||
}
|
||||
|
||||
await mermaid.initialize({ startOnLoad: false });
|
||||
loaded = true;
|
||||
});
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user