diff --git a/app/src/components/Markdown.tsx b/app/src/components/Markdown.tsx index 037de3d..d3f0ee8 100644 --- a/app/src/components/Markdown.tsx +++ b/app/src/components/Markdown.tsx @@ -68,21 +68,34 @@ function Markdown({ className, loading, }: MarkdownProps) { - // memoize the component + const processedContent = useMemo(() => { + let content = children; + + // Inline math: replace \(...\) with $ ... $ + content = content.replace(/\\\((.*?)\\\)/g, (_, equation) => `$ ${equation.trim()} $`); + + // Block math: replace \[...\] with $$...$$ on separate lines + content = content.replace( + /\s*\\\[\s*([\s\S]*?)\s*\\\]\s*/g, + (_, equation) => `\n$$\n${equation.trim()}\n$$\n` + ); + + return content; + }, [children]); + return useMemo( () => ( ), - [children, acceptHtml, codeStyle, className, loading], + [processedContent, acceptHtml, codeStyle, className, loading], ); } - type CodeMarkdownProps = MarkdownProps & { filename: string; };