diff --git a/frontend/src/conversation/ConversationBubble.tsx b/frontend/src/conversation/ConversationBubble.tsx index 75cf2633..0a0d0780 100644 --- a/frontend/src/conversation/ConversationBubble.tsx +++ b/frontend/src/conversation/ConversationBubble.tsx @@ -1,6 +1,6 @@ import 'katex/dist/katex.min.css'; -import { forwardRef, useRef, useState } from 'react'; +import { forwardRef, Fragment, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; import ReactMarkdown from 'react-markdown'; import { useSelector } from 'react-redux'; @@ -193,6 +193,33 @@ const ConversationBubble = forwardRef< return inlineProcessedContent; }; + const processMarkdownContent = (content: string) => { + const processedContent = preprocessLaTeX(content); + + const contentSegments: Array<{type: 'text' | 'mermaid', content: string}> = []; + + let lastIndex = 0; + const regex = /```mermaid\n([\s\S]*?)```/g; + let match; + + while ((match = regex.exec(processedContent)) !== null) { + const textBefore = processedContent.substring(lastIndex, match.index); + if (textBefore) { + contentSegments.push({ type: 'text', content: textBefore }); + } + + contentSegments.push({ type: 'mermaid', content: match[1].trim() }); + + lastIndex = match.index + match[0].length; + } + + const textAfter = processedContent.substring(lastIndex); + if (textAfter) { + contentSegments.push({ type: 'text', content: textAfter }); + } + + return contentSegments; + }; bubble = (
- {children}
-
- );
- },
- ul({ children }) {
- return (
-
+ {children}
+
+ );
+ },
+ ul({ children }) {
+ return (
+