perf(ui): hoist marked.use() to module scope to prevent extension stacking (#25837)
This commit is contained in:
1 file changed
+28
-25
@@ -1,19 +1,41 @@
|
|||||||
<script>
|
<script context="module">
|
||||||
import { onDestroy } from 'svelte';
|
|
||||||
import { marked } from 'marked';
|
import { marked } from 'marked';
|
||||||
import { replaceTokens, processResponseContent } from '$lib/utils';
|
|
||||||
import { user } from '$lib/stores';
|
|
||||||
|
|
||||||
import markedExtension from '$lib/utils/marked/extension';
|
import markedExtension from '$lib/utils/marked/extension';
|
||||||
import markedKatexExtension from '$lib/utils/marked/katex-extension';
|
import markedKatexExtension from '$lib/utils/marked/katex-extension';
|
||||||
import { disableSingleTilde } from '$lib/utils/marked/strikethrough-extension';
|
import { disableSingleTilde } from '$lib/utils/marked/strikethrough-extension';
|
||||||
import { mentionExtension } from '$lib/utils/marked/mention-extension';
|
import { mentionExtension } from '$lib/utils/marked/mention-extension';
|
||||||
import colonFenceExtension from '$lib/utils/marked/colon-fence-extension';
|
import colonFenceExtension from '$lib/utils/marked/colon-fence-extension';
|
||||||
|
|
||||||
import MarkdownTokens from './Markdown/MarkdownTokens.svelte';
|
|
||||||
import footnoteExtension from '$lib/utils/marked/footnote-extension';
|
import footnoteExtension from '$lib/utils/marked/footnote-extension';
|
||||||
import citationExtension from '$lib/utils/marked/citation-extension';
|
import citationExtension from '$lib/utils/marked/citation-extension';
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
throwOnError: false,
|
||||||
|
breaks: true
|
||||||
|
};
|
||||||
|
|
||||||
|
marked.use(markedKatexExtension(options));
|
||||||
|
marked.use(markedExtension(options));
|
||||||
|
marked.use(citationExtension(options));
|
||||||
|
marked.use(footnoteExtension(options));
|
||||||
|
marked.use(colonFenceExtension(options));
|
||||||
|
marked.use(disableSingleTilde);
|
||||||
|
marked.use({
|
||||||
|
extensions: [
|
||||||
|
mentionExtension({ triggerChar: '@' }),
|
||||||
|
mentionExtension({ triggerChar: '#' }),
|
||||||
|
mentionExtension({ triggerChar: '$' })
|
||||||
|
]
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { onDestroy } from 'svelte';
|
||||||
|
import { replaceTokens, processResponseContent } from '$lib/utils';
|
||||||
|
import { user } from '$lib/stores';
|
||||||
|
|
||||||
|
import MarkdownTokens from './Markdown/MarkdownTokens.svelte';
|
||||||
|
|
||||||
export let id = '';
|
export let id = '';
|
||||||
export let content;
|
export let content;
|
||||||
export let done = true;
|
export let done = true;
|
||||||
@@ -41,25 +63,6 @@
|
|||||||
let lastContent = '';
|
let lastContent = '';
|
||||||
let lastParsedContent = '';
|
let lastParsedContent = '';
|
||||||
|
|
||||||
const options = {
|
|
||||||
throwOnError: false,
|
|
||||||
breaks: true
|
|
||||||
};
|
|
||||||
|
|
||||||
marked.use(markedKatexExtension(options));
|
|
||||||
marked.use(markedExtension(options));
|
|
||||||
marked.use(citationExtension(options));
|
|
||||||
marked.use(footnoteExtension(options));
|
|
||||||
marked.use(colonFenceExtension(options));
|
|
||||||
marked.use(disableSingleTilde);
|
|
||||||
marked.use({
|
|
||||||
extensions: [
|
|
||||||
mentionExtension({ triggerChar: '@' }),
|
|
||||||
mentionExtension({ triggerChar: '#' }),
|
|
||||||
mentionExtension({ triggerChar: '$' })
|
|
||||||
]
|
|
||||||
});
|
|
||||||
|
|
||||||
const parseTokens = () => {
|
const parseTokens = () => {
|
||||||
if (content === lastContent) return;
|
if (content === lastContent) return;
|
||||||
lastContent = content;
|
lastContent = content;
|
||||||
|
|||||||
Reference in new issue
Block a user