|
1 | | -<script> |
| 1 | +<script context="module"> |
2 | 2 | import { marked } from 'marked'; |
3 | | - import { replaceTokens, processResponseContent } from '$lib/utils'; |
4 | | - import { user } from '$lib/stores'; |
5 | 3 |
|
6 | 4 | import markedExtension from '$lib/utils/marked/extension'; |
7 | 5 | import markedKatexExtension from '$lib/utils/marked/katex-extension'; |
8 | 6 | import { disableSingleTilde } from '$lib/utils/marked/strikethrough-extension'; |
9 | 7 | import { mentionExtension } from '$lib/utils/marked/mention-extension'; |
10 | | -
|
11 | | - import MarkdownTokens from './Markdown/MarkdownTokens.svelte'; |
12 | 8 | import footnoteExtension from '$lib/utils/marked/footnote-extension'; |
13 | 9 | import citationExtension from '$lib/utils/marked/citation-extension'; |
14 | 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 | +
|
| 30 | + import MarkdownTokens from './Markdown/MarkdownTokens.svelte'; |
| 31 | +
|
15 | 32 | export let id = ''; |
16 | 33 | export let content; |
17 | 34 | export let done = true; |
|
35 | 52 |
|
36 | 53 | let tokens = []; |
37 | 54 |
|
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 | | - })(); |
| 55 | + $: if (content) { |
| 56 | + tokens = marked.lexer( |
| 57 | + replaceTokens(processResponseContent(content), model?.name, $user?.name) |
| 58 | + ); |
| 59 | + } |
59 | 60 | </script> |
60 | 61 |
|
61 | 62 | {#key id} |
|
0 commit comments