open-webui/src/lib/components/chat/Messages/Markdown.svelte
2024-09-30 12:50:53 +02:00

36 lines
778 B
Svelte

<script>
import { marked } from 'marked';
import { replaceTokens, processResponseContent } from '$lib/utils';
import { user } from '$lib/stores';
import markedExtension from '$lib/utils/marked/extension';
import markedKatexExtension from '$lib/utils/marked/katex-extension';
import MarkdownTokens from './Markdown/MarkdownTokens.svelte';
export let id;
export let content;
export let model = null;
let tokens = [];
const options = {
throwOnError: false
};
marked.use(markedKatexExtension(options));
marked.use(markedExtension(options));
$: (async () => {
if (content) {
tokens = marked.lexer(
replaceTokens(processResponseContent(content), model?.name, $user?.name)
);
}
})();
</script>
{#key id}
<MarkdownTokens {tokens} {id} />
{/key}