Преглед изворни кода

feat: support Latex (#5001)

Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com>
tags/0.6.12
Nam Vu пре 1 година
родитељ
комит
3828d4cd22
No account linked to committer's email address
1 измењених фајлова са 8 додато и 2 уклоњено
  1. 8
    2
      web/app/components/base/markdown.tsx

+ 8
- 2
web/app/components/base/markdown.tsx Прегледај датотеку

@@ -39,6 +39,11 @@ const getCorrectCapitalizationLanguageName = (language: string) => {

return language.charAt(0).toUpperCase() + language.substring(1)
}

const preprocessLaTeX = (content: string) =>
content.replace(/\\\[(.*?)\\\]/gs, (_, equation) => `$$${equation}$$`)
.replace(/\\\((.*?)\\\)/gs, (_, equation) => `$${equation}$`)

export function PreCode(props: { children: any }) {
const ref = useRef<HTMLPreElement>(null)

@@ -82,12 +87,13 @@ const useLazyLoad = (ref: RefObject<Element>): boolean => {

export function Markdown(props: { content: string; className?: string }) {
const [isSVG, setIsSVG] = useState(false)
const latexContent = preprocessLaTeX(props.content)
return (
<div className={cn(props.className, 'markdown-body')}>
<ReactMarkdown
remarkPlugins={[[RemarkMath, { singleDollarTextMath: false }], RemarkGfm, RemarkBreaks]}
rehypePlugins={[
RehypeKatex,
RehypeKatex as any,
]}
components={{
code({ inline, className, children, ...props }) {
@@ -179,7 +185,7 @@ export function Markdown(props: { content: string; className?: string }) {
linkTarget='_blank'
>
{/* Markdown detect has problem. */}
{props.content}
{latexContent}
</ReactMarkdown>
</div>
)

Loading…
Откажи
Сачувај