Explorar el Código

feat: support Latex (#5001)

Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com>
tags/0.6.12
Nam Vu hace 1 año
padre
commit
3828d4cd22
No account linked to committer's email address
Se han modificado 1 ficheros con 8 adiciones y 2 borrados
  1. 8
    2
      web/app/components/base/markdown.tsx

+ 8
- 2
web/app/components/base/markdown.tsx Ver fichero



return language.charAt(0).toUpperCase() + language.substring(1) 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 }) { export function PreCode(props: { children: any }) {
const ref = useRef<HTMLPreElement>(null) const ref = useRef<HTMLPreElement>(null)




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

Cargando…
Cancelar
Guardar