From 9747f1e8415798dbb7be6ed5c215d32664db28cc Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Tue, 6 Aug 2024 23:34:51 +0200 Subject: [PATCH] revert: markdown rendering --- .../chat/Messages/MarkdownInlineTokens.svelte | 6 - .../chat/Messages/MarkdownTokens.svelte | 135 +++++++++++------- .../chat/Messages/ResponseMessage.svelte | 20 ++- 3 files changed, 93 insertions(+), 68 deletions(-) diff --git a/src/lib/components/chat/Messages/MarkdownInlineTokens.svelte b/src/lib/components/chat/Messages/MarkdownInlineTokens.svelte index 7ccc0e565..19d22de37 100644 --- a/src/lib/components/chat/Messages/MarkdownInlineTokens.svelte +++ b/src/lib/components/chat/Messages/MarkdownInlineTokens.svelte @@ -1,16 +1,10 @@ {#each tokens as token} diff --git a/src/lib/components/chat/Messages/MarkdownTokens.svelte b/src/lib/components/chat/Messages/MarkdownTokens.svelte index fd86a586c..a182e5cd5 100644 --- a/src/lib/components/chat/Messages/MarkdownTokens.svelte +++ b/src/lib/components/chat/Messages/MarkdownTokens.svelte @@ -1,4 +1,5 @@ -{#each tokens as token, tokenIdx} - {#if token.type === 'hr'} -
- {:else if token.type === 'heading'} +{#each tokens as token, tokenIdx (`${id}-${tokenIdx}`)} + {#if token.type === 'code'} + {#if token.lang === 'mermaid'} +
{revertSanitizedResponseContent(token.text)}
+ {:else} + + {/if} + + {:else} - {console.log('Unknown token', token)} + {@html marked.parse(token.raw, { + ...defaults, + gfm: true, + breaks: true, + renderer + })} {/if} {/each} diff --git a/src/lib/components/chat/Messages/ResponseMessage.svelte b/src/lib/components/chat/Messages/ResponseMessage.svelte index a0cadaf27..99c2e3f5b 100644 --- a/src/lib/components/chat/Messages/ResponseMessage.svelte +++ b/src/lib/components/chat/Messages/ResponseMessage.svelte @@ -77,9 +77,16 @@ let selectedCitation = null; - $: tokens = marked.lexer( - replaceTokens(sanitizeResponseContent(message?.content), model?.name, $user?.name) - ); + let tokens; + + $: (async () => { + if (message?.content) { + tokens = marked.lexer( + replaceTokens(sanitizeResponseContent(message?.content), model?.name, $user?.name) + ); + // console.log(message?.content, tokens); + } + })(); $: if (message) { renderStyling(); @@ -413,7 +420,7 @@ {/if}
{#if (message?.statusHistory ?? [...(message?.status ? [message?.status] : [])]).length > 0} @@ -493,14 +500,13 @@
{:else} -
+
{#if message.content === '' && !message.error} {:else if message.content && message.error !== true} - - {#key tokens} + {#key message.id} {/key} {/if}