Skip to content

Commit de16cca

Browse files
committed
added render button
1 parent 32087eb commit de16cca

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/lib/EditMessage.svelte

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import SvelteMarkdown from 'svelte-markdown'
88
import type { Message, Model, Chat } from './Types.svelte'
99
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'
1111
import { errorNotice, scrollToMessage } from './Util.svelte'
1212
import { openModal } from 'svelte-modals'
1313
import PromptConfirm from './PromptConfirm.svelte'
@@ -20,8 +20,6 @@
2020
export let chatId:number
2121
export let chat:Chat
2222
23-
const renderLatexFlag = import.meta.env.VITE_RENDER_LATEX || true
24-
2523
$: chatSettings = chat.settings
2624
2725
const isError = message.role === 'error'
@@ -226,9 +224,6 @@
226224
}
227225
228226
const preprocessMath = (text: string): string => {
229-
if (renderLatexFlag !== true) {
230-
return text
231-
}
232227
let codeBlockPlaceholderPrefix = '__prefix__c0d3b10ck__'
233228
while (text.indexOf(codeBlockPlaceholderPrefix) > 0) {
234229
codeBlockPlaceholderPrefix = codeBlockPlaceholderPrefix + '_'
@@ -275,6 +270,10 @@
275270
return text
276271
}
277272
273+
const renderMathMsg = () => {
274+
displayMessage = preprocessMath(message.content);
275+
};
276+
278277
</script>
279278

280279
<article
@@ -314,7 +313,7 @@
314313
{/if}
315314
{#key refreshCounter}
316315
<SvelteMarkdown
317-
source={preprocessMath(displayMessage)}
316+
bind:source={displayMessage}
318317
options={markdownOptions}
319318
renderers={renderers}
320319
/>
@@ -432,6 +431,16 @@
432431
<span class="icon"><Fa icon={faClipboard} /></span>
433432
</a>
434433
{/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>
435444
{#if imageUrl}
436445
<a
437446
href={'#'}

0 commit comments

Comments
 (0)