From a6af20e1eb3a4faade1488730acda46f0eca693a Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sat, 25 May 2024 02:47:09 -0700 Subject: [PATCH] fix: codeblock rendering issue --- .../components/chat/Messages/CodeBlock.svelte | 105 +++++++++--------- .../chat/Messages/ResponseMessage.svelte | 4 +- 2 files changed, 55 insertions(+), 54 deletions(-) diff --git a/src/lib/components/chat/Messages/CodeBlock.svelte b/src/lib/components/chat/Messages/CodeBlock.svelte index 5881d109e..fe6c277f1 100644 --- a/src/lib/components/chat/Messages/CodeBlock.svelte +++ b/src/lib/components/chat/Messages/CodeBlock.svelte @@ -4,7 +4,7 @@ import hljs from 'highlight.js'; import 'highlight.js/styles/github-dark.min.css'; import { loadPyodide } from 'pyodide'; - import { tick } from 'svelte'; + import { onMount, tick } from 'svelte'; import PyodideWorker from '$lib/workers/pyodide.worker?worker'; export let id = ''; @@ -12,6 +12,7 @@ export let lang = ''; export let code = ''; + let highlightedCode = null; let executing = false; let stdout = null; @@ -202,60 +203,60 @@ __builtins__.input = input`); }; }; - $: highlightedCode = code ? hljs.highlightAuto(code, hljs.getLanguage(lang)?.aliases).value : ''; + $: if (code) { + highlightedCode = hljs.highlightAuto(code, hljs.getLanguage(lang)?.aliases).value || code; + } -{#if code} -
-
-
{@html lang}
+
+
+
{@html lang}
-
- {#if lang === 'python' || (lang === '' && checkPythonCode(code))} - {#if executing} -
Running
- {:else} - - {/if} +
+ {#if lang === 'python' || (lang === '' && checkPythonCode(code))} + {#if executing} +
Running
+ {:else} + {/if} - -
+ {/if} +
- -
{@html highlightedCode || code}
- -
- - {#if executing} -
-
STDOUT/STDERR
-
Running...
-
- {:else if stdout || stderr || result} -
-
STDOUT/STDERR
-
{stdout || stderr || result}
-
- {/if}
-{/if} + +
{@html highlightedCode || code}
+ +
+ + {#if executing} +
+
STDOUT/STDERR
+
Running...
+
+ {:else if stdout || stderr || result} +
+
STDOUT/STDERR
+
{stdout || stderr || result}
+
+ {/if} +
diff --git a/src/lib/components/chat/Messages/ResponseMessage.svelte b/src/lib/components/chat/Messages/ResponseMessage.svelte index 44bcea038..f1693a94f 100644 --- a/src/lib/components/chat/Messages/ResponseMessage.svelte +++ b/src/lib/components/chat/Messages/ResponseMessage.svelte @@ -440,8 +440,8 @@ {#if token.type === 'code'} {:else} {@html marked.parse(token.raw, {