|
7 | 7 | import SvelteMarkdown from 'svelte-markdown'
|
8 | 8 | import type { Message, Model, Chat } from './Types.svelte'
|
9 | 9 | import Fa from 'svelte-fa/src/fa.svelte'
|
10 |
| - import { faTrash, faDiagramPredecessor, faDiagramNext, faCircleCheck, faPaperPlane, faEye, faEyeSlash, faEllipsis, faDownload, faClipboard } from '@fortawesome/free-solid-svg-icons/index' |
| 10 | + import { faTrash, faDiagramPredecessor, faDiagramNext, faCircleCheck, faPaperPlane, faEye, faEyeSlash, faEllipsis, faDownload, faClipboard, faSquareRootVariable } from '@fortawesome/free-solid-svg-icons/index' |
11 | 11 | import { errorNotice, scrollToMessage } from './Util.svelte'
|
12 | 12 | import { openModal } from 'svelte-modals'
|
13 | 13 | import PromptConfirm from './PromptConfirm.svelte'
|
|
20 | 20 | export let chatId:number
|
21 | 21 | export let chat:Chat
|
22 | 22 |
|
23 |
| - const renderLatexFlag = import.meta.env.VITE_RENDER_LATEX || true |
24 |
| -
|
25 | 23 | $: chatSettings = chat.settings
|
26 | 24 |
|
27 | 25 | const isError = message.role === 'error'
|
|
226 | 224 | }
|
227 | 225 |
|
228 | 226 | const preprocessMath = (text: string): string => {
|
229 |
| - if (renderLatexFlag !== true) { |
230 |
| - return text |
231 |
| - } |
232 | 227 | let codeBlockPlaceholderPrefix = '__prefix__c0d3b10ck__'
|
233 | 228 | while (text.indexOf(codeBlockPlaceholderPrefix) > 0) {
|
234 | 229 | codeBlockPlaceholderPrefix = codeBlockPlaceholderPrefix + '_'
|
|
275 | 270 | return text
|
276 | 271 | }
|
277 | 272 |
|
| 273 | + const renderMathMsg = () => { |
| 274 | + displayMessage = preprocessMath(message.content); |
| 275 | + }; |
| 276 | +
|
278 | 277 | </script>
|
279 | 278 |
|
280 | 279 | <article
|
|
314 | 313 | {/if}
|
315 | 314 | {#key refreshCounter}
|
316 | 315 | <SvelteMarkdown
|
317 |
| - source={preprocessMath(displayMessage)} |
| 316 | + bind:source={displayMessage} |
318 | 317 | options={markdownOptions}
|
319 | 318 | renderers={renderers}
|
320 | 319 | />
|
|
432 | 431 | <span class="icon"><Fa icon={faClipboard} /></span>
|
433 | 432 | </a>
|
434 | 433 | {/if}
|
| 434 | + <a |
| 435 | + href={'#'} |
| 436 | + title="Render LaTeX in message" |
| 437 | + class="button is-small" |
| 438 | + on:click|preventDefault={() => { |
| 439 | + renderMathMsg() |
| 440 | + }} |
| 441 | + > |
| 442 | + <span class="icon"><Fa icon={faSquareRootVariable} /></span> |
| 443 | + </a> |
435 | 444 | {#if imageUrl}
|
436 | 445 | <a
|
437 | 446 | href={'#'}
|
|
0 commit comments