open-webui/src/lib/components/chat/Messages/Markdown.svelte

50 lines
1.0 KiB
Svelte
Raw Normal View History

2024-08-18 18:59:59 +00:00
<script>
import { marked } from 'marked';
import { replaceTokens, processResponseContent } from '$lib/utils';
import { user } from '$lib/stores';
2024-09-30 10:50:53 +00:00
import markedExtension from '$lib/utils/marked/extension';
import markedKatexExtension from '$lib/utils/marked/katex-extension';
2024-08-18 18:59:59 +00:00
import MarkdownTokens from './Markdown/MarkdownTokens.svelte';
2024-10-05 19:04:36 +00:00
import { createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher();
2024-08-18 18:59:59 +00:00
export let id;
export let content;
export let model = null;
2024-10-05 19:07:45 +00:00
export let save = false;
2024-08-18 18:59:59 +00:00
let tokens = [];
const options = {
throwOnError: false
};
2024-09-30 10:50:53 +00:00
marked.use(markedKatexExtension(options));
marked.use(markedExtension(options));
2024-08-18 18:59:59 +00:00
$: (async () => {
if (content) {
tokens = marked.lexer(
replaceTokens(processResponseContent(content), model?.name, $user?.name)
);
}
})();
</script>
{#key id}
2024-10-05 19:04:36 +00:00
<MarkdownTokens
{tokens}
{id}
2024-10-05 19:07:45 +00:00
{save}
2024-10-05 19:04:36 +00:00
on:update={(e) => {
dispatch('update', e.detail);
}}
2024-10-06 07:14:05 +00:00
on:code={(e) => {
dispatch('code', e.detail);
}}
2024-10-05 19:04:36 +00:00
/>
2024-08-18 18:59:59 +00:00
{/key}