|
| 1 | +<script lang="ts" context="module"> |
| 2 | + import { marked, type Token } from 'marked'; |
| 3 | + import { decode } from 'html-entities'; |
| 4 | +
|
| 5 | + const _detailsLexCache = new Map<string, Token[]>(); |
| 6 | + const cachedLex = (text: string): Token[] => { |
| 7 | + const cached = _detailsLexCache.get(text); |
| 8 | + if (cached) return cached; |
| 9 | + const result = marked.lexer(decode(text)); |
| 10 | + if (_detailsLexCache.size > 50) _detailsLexCache.clear(); |
| 11 | + _detailsLexCache.set(text, result); |
| 12 | + return result; |
| 13 | + }; |
| 14 | +</script> |
| 15 | + |
1 | 16 | <script lang="ts"> |
2 | 17 | import { decode } from 'html-entities'; |
3 | 18 | import { onMount, getContext } from 'svelte'; |
|
6 | 21 | import fileSaver from 'file-saver'; |
7 | 22 | const { saveAs } = fileSaver; |
8 | 23 |
|
9 | | - import { marked, type Token } from 'marked'; |
| 24 | + import { type Token } from 'marked'; |
10 | 25 | import { copyToClipboard, unescapeHtml } from '$lib/utils'; |
11 | 26 |
|
12 | 27 | import { WEBUI_BASE_URL } from '$lib/constants'; |
|
393 | 408 | <div class="mb-1.5" slot="content"> |
394 | 409 | <svelte:self |
395 | 410 | id={`${id}-${tokenIdx}-${detailIdx}-d`} |
396 | | - tokens={marked.lexer(decode(detailToken.text))} |
| 411 | + tokens={cachedLex(detailToken.text)} |
397 | 412 | attributes={detailToken?.attributes} |
398 | 413 | {done} |
399 | 414 | {editCodeBlock} |
|
440 | 455 | <div class=" mb-1.5" slot="content"> |
441 | 456 | <svelte:self |
442 | 457 | id={`${id}-${tokenIdx}-d`} |
443 | | - tokens={marked.lexer(decode(token.text))} |
| 458 | + tokens={cachedLex(token.text)} |
444 | 459 | attributes={token?.attributes} |
445 | 460 | {done} |
446 | 461 | {editCodeBlock} |
|
0 commit comments