Skip to content

Commit

Permalink
added render button
Browse files Browse the repository at this point in the history
  • Loading branch information
morgan9e committed Apr 26, 2024
1 parent 32087eb commit bea863c
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/lib/EditMessage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@
import SvelteMarkdown from 'svelte-markdown'
import type { Message, Model, Chat } from './Types.svelte'
import Fa from 'svelte-fa/src/fa.svelte'
import { faTrash, faDiagramPredecessor, faDiagramNext, faCircleCheck, faPaperPlane, faEye, faEyeSlash, faEllipsis, faDownload, faClipboard } from '@fortawesome/free-solid-svg-icons/index'
import { faTrash, faDiagramPredecessor, faDiagramNext, faCircleCheck, faPaperPlane, faEye, faEyeSlash, faEllipsis, faDownload, faClipboard, faSquareRootVariable } from '@fortawesome/free-solid-svg-icons/index'
import { errorNotice, scrollToMessage } from './Util.svelte'
import { openModal } from 'svelte-modals'
import PromptConfirm from './PromptConfirm.svelte'
import { getImage } from './ImageStore.svelte'
import { getModelDetail } from './Models.svelte'
import 'katex/dist/katex.min.css'
import renderMathInElement from 'katex/contrib/auto-render/auto-render.js'
export let message:Message
export let chatId:number
export let chat:Chat
const renderLatexFlag = import.meta.env.VITE_RENDER_LATEX || true
$: chatSettings = chat.settings
const isError = message.role === 'error'
Expand Down Expand Up @@ -226,9 +225,6 @@
}
const preprocessMath = (text: string): string => {
if (renderLatexFlag !== true) {
return text
}
let codeBlockPlaceholderPrefix = '__prefix__c0d3b10ck__'
while (text.indexOf(codeBlockPlaceholderPrefix) > 0) {
codeBlockPlaceholderPrefix = codeBlockPlaceholderPrefix + '_'
Expand Down Expand Up @@ -275,6 +271,10 @@
return text
}
const renderMathMsg = () => {
displayMessage = preprocessMath(message.content);
};
</script>

<article
Expand Down Expand Up @@ -314,7 +314,7 @@
{/if}
{#key refreshCounter}
<SvelteMarkdown
source={preprocessMath(displayMessage)}
bind:source={displayMessage}
options={markdownOptions}
renderers={renderers}
/>
Expand Down Expand Up @@ -432,6 +432,18 @@
<span class="icon"><Fa icon={faClipboard} /></span>
</a>
{/if}

<a
href={'#'}
title="Render LaTeX in message"
class="button is-small"
on:click|preventDefault={() => {
renderMathMsg()
}}
>
<span class="icon"><Fa icon={faSquareRootVariable} /></span>
</a>

{#if imageUrl}
<a
href={'#'}
Expand Down

0 comments on commit bea863c

Please sign in to comment.