From 56582e6f5e5e6470786b09c3d6d32cc95628381e Mon Sep 17 00:00:00 2001
From: cogentapps <127109874+cogentapps@users.noreply.github.com>
Date: Sun, 2 Jul 2023 08:00:39 +0000
Subject: [PATCH] make katex optional
---
app/src/components/markdown.tsx | 21 +++++++++++++++------
app/src/components/message.tsx | 7 ++++++-
app/src/global-options/index.tsx | 3 ++-
app/src/global-options/ui.tsx | 16 ++++++++++++++++
4 files changed, 39 insertions(+), 8 deletions(-)
diff --git a/app/src/components/markdown.tsx b/app/src/components/markdown.tsx
index 74ed7b0..b38b833 100644
--- a/app/src/components/markdown.tsx
+++ b/app/src/components/markdown.tsx
@@ -53,6 +53,7 @@ const ImagePreview = styled.div`
export interface MarkdownProps {
content: string;
className?: string;
+ katex? : boolean;
}
export function Markdown(props: MarkdownProps) {
@@ -68,11 +69,19 @@ export function Markdown(props: MarkdownProps) {
return classes;
}, [props.className])
- const elem = useMemo(() => (
-
+ const elem = useMemo(() => {
+ const remarkPlugins: any[] = [remarkGfm];
+ const rehypePlugins: any[] = [];
+
+ if (props.katex) {
+ remarkPlugins.push(remarkMath);
+ rehypePlugins.push(rehypeKatex);
+ }
+
+ return
@@ -129,8 +138,8 @@ export function Markdown(props: MarkdownProps) {
)
}
}}>{props.content}
-
- ), [props.content, classes, intl]);
+
;
+ }, [props.content, props.katex, classes, intl]);
return elem;
}
diff --git a/app/src/components/message.tsx b/app/src/components/message.tsx
index 4650713..9567aac 100644
--- a/app/src/components/message.tsx
+++ b/app/src/components/message.tsx
@@ -1,6 +1,7 @@
import styled from '@emotion/styled';
import { Button, CopyButton, Loader, Textarea } from '@mantine/core';
+import { useOption } from '../core/options/use-option';
import { Message } from "../core/chat/types";
import { share } from '../core/utils';
import { TTSButton } from './tts-button';
@@ -210,6 +211,8 @@ export default function MessageComponent(props: { message: Message, last: boolea
const [content, setContent] = useState('');
const intl = useIntl();
+ const [katex] = useOption('markdown', 'katex');
+
const tab = useAppSelector(selectSettingsTab);
const getRoleName = useCallback((role: string, share = false) => {
@@ -288,7 +291,9 @@ export default function MessageComponent(props: { message: Message, last: boolea
)}
- {!editing && }
+ {!editing && }
{editing && (