feat: add LaTeX extension support via Marked (#2766)

This commit is contained in:
Louis 2024-04-21 18:18:57 +07:00 committed by GitHub
parent 54af9f9e43
commit 7725347cdb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 2 deletions

View File

@ -23,10 +23,12 @@
"framer-motion": "^10.16.4",
"highlight.js": "^11.9.0",
"jotai": "^2.6.0",
"katex": "^0.16.10",
"lodash": "^4.17.21",
"lucide-react": "^0.291.0",
"marked": "^9.1.2",
"marked-highlight": "^2.0.6",
"marked-katex-extension": "^5.0.1",
"next": "14.0.1",
"next-themes": "^0.2.1",
"postcss": "8.4.31",

View File

@ -19,8 +19,8 @@ import hljs from 'highlight.js'
import { useAtomValue } from 'jotai'
import { FolderOpenIcon } from 'lucide-react'
import { Marked, Renderer } from 'marked'
import { markedHighlight } from 'marked-highlight'
import markedKatex from 'marked-katex-extension'
import { twMerge } from 'tailwind-merge'
@ -100,6 +100,8 @@ const SimpleTextMessage: React.FC<ThreadMessage> = (props) => {
}
)
marked.use(markedKatex({ throwOnError: false }))
const { onViewFile, onViewFileContainer } = usePath()
const parsedText = marked.parse(text)
const [tokenCount, setTokenCount] = useState(0)
@ -297,7 +299,7 @@ const SimpleTextMessage: React.FC<ThreadMessage> = (props) => {
) : (
<div
className={twMerge(
'message flex flex-grow flex-col gap-y-2 text-[15px] font-normal leading-relaxed',
'message max-width-[100%] flex flex-grow flex-col gap-y-2 overflow-auto text-[15px] font-normal leading-relaxed',
isUser
? 'whitespace-pre-wrap break-words'
: 'rounded-xl bg-secondary p-4'