Skip to content

Commit 24482b4

Browse files
committed
Revert "perf: move marked extension registration to module-level and remove unnecessary async wrapper"
This reverts commit 2ef2b8b.
1 parent 69c07f6 commit 24482b4

1 file changed

Lines changed: 26 additions & 27 deletions

File tree

src/lib/components/chat/Messages/Markdown.svelte

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,16 @@
1-
<script context="module">
1+
<script>
22
import { marked } from 'marked';
3+
import { replaceTokens, processResponseContent } from '$lib/utils';
4+
import { user } from '$lib/stores';
35
46
import markedExtension from '$lib/utils/marked/extension';
57
import markedKatexExtension from '$lib/utils/marked/katex-extension';
68
import { disableSingleTilde } from '$lib/utils/marked/strikethrough-extension';
79
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';
2910
3011
import MarkdownTokens from './Markdown/MarkdownTokens.svelte';
12+
import footnoteExtension from '$lib/utils/marked/footnote-extension';
13+
import citationExtension from '$lib/utils/marked/citation-extension';
3114
3215
export let id = '';
3316
export let content;
@@ -52,11 +35,27 @@
5235
5336
let tokens = [];
5437
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+
})();
6059
</script>
6160
6261
{#key id}

0 commit comments

Comments
 (0)