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