|
1 | | -<script context="module"> |
| 1 | +<script> |
2 | 2 | import { marked } from 'marked'; |
| 3 | + import { replaceTokens, processResponseContent } from '$lib/utils'; |
| 4 | + import { user } from '$lib/stores'; |
3 | 5 |
|
4 | 6 | import markedExtension from '$lib/utils/marked/extension'; |
5 | 7 | import markedKatexExtension from '$lib/utils/marked/katex-extension'; |
6 | 8 | import { disableSingleTilde } from '$lib/utils/marked/strikethrough-extension'; |
7 | 9 | import { mentionExtension } from '$lib/utils/marked/mention-extension'; |
8 | | - import footnoteExtension from '$lib/utils/marked/footnote-extension'; |
9 | | - import citationExtension from '$lib/utils/marked/citation-extension'; |
10 | | -
|
11 | | - const options = { |
12 | | - throwOnError: false, |
13 | | - breaks: true |
14 | | - }; |
15 | | -
|
16 | | - marked.use(markedKatexExtension(options)); |
17 | | - marked.use(markedExtension(options)); |
18 | | - marked.use(citationExtension(options)); |
19 | | - marked.use(footnoteExtension(options)); |
20 | | - marked.use(disableSingleTilde); |
21 | | - marked.use({ |
22 | | - extensions: [mentionExtension({ triggerChar: '@' }), mentionExtension({ triggerChar: '#' })] |
23 | | - }); |
24 | | -</script> |
25 | | - |
26 | | -<script> |
27 | | - import { replaceTokens, processResponseContent } from '$lib/utils'; |
28 | | - import { user } from '$lib/stores'; |
29 | 10 |
|
30 | 11 | import MarkdownTokens from './Markdown/MarkdownTokens.svelte'; |
| 12 | + import footnoteExtension from '$lib/utils/marked/footnote-extension'; |
| 13 | + import citationExtension from '$lib/utils/marked/citation-extension'; |
31 | 14 |
|
32 | 15 | export let id = ''; |
33 | 16 | export let content; |
|
52 | 35 |
|
53 | 36 | let tokens = []; |
54 | 37 |
|
55 | | - $: if (content) { |
56 | | - tokens = marked.lexer( |
57 | | - replaceTokens(processResponseContent(content), model?.name, $user?.name) |
58 | | - ); |
59 | | - } |
| 38 | + const options = { |
| 39 | + throwOnError: false, |
| 40 | + breaks: true |
| 41 | + }; |
| 42 | +
|
| 43 | + marked.use(markedKatexExtension(options)); |
| 44 | + marked.use(markedExtension(options)); |
| 45 | + marked.use(citationExtension(options)); |
| 46 | + marked.use(footnoteExtension(options)); |
| 47 | + marked.use(disableSingleTilde); |
| 48 | + marked.use({ |
| 49 | + extensions: [mentionExtension({ triggerChar: '@' }), mentionExtension({ triggerChar: '#' })] |
| 50 | + }); |
| 51 | +
|
| 52 | + $: (async () => { |
| 53 | + if (content) { |
| 54 | + tokens = marked.lexer( |
| 55 | + replaceTokens(processResponseContent(content), model?.name, $user?.name) |
| 56 | + ); |
| 57 | + } |
| 58 | + })(); |
60 | 59 | </script> |
61 | 60 |
|
62 | 61 | {#key id} |
|
0 commit comments