diff --git a/web/screens/Thread/ThreadCenterPanel/TextMessage/MarkdownTextMessage.tsx b/web/screens/Thread/ThreadCenterPanel/TextMessage/MarkdownTextMessage.tsx
index 76e75f2a28..f0a23e4160 100644
--- a/web/screens/Thread/ThreadCenterPanel/TextMessage/MarkdownTextMessage.tsx
+++ b/web/screens/Thread/ThreadCenterPanel/TextMessage/MarkdownTextMessage.tsx
@@ -19,9 +19,15 @@ import { useClipboard } from '@/hooks/useClipboard'
import { getLanguageFromExtension } from '@/utils/codeLanguageExtension'
export const MarkdownTextMessage = memo(
- ({ text }: { id: string; text: string }) => {
+ ({ text, isUser }: { id: string; text: string; isUser: boolean }) => {
const clipboard = useClipboard({ timeout: 1000 })
+ // Escapes headings
+ function preprocessMarkdown(text: string): string {
+ if (!isUser) return text
+ return text.replace(/^#{1,6} /gm, (match) => `\\${match}`)
+ }
+
function extractCodeLines(node: { children: { children: any[] }[] }) {
const codeLines: any[] = []
@@ -204,7 +210,7 @@ export const MarkdownTextMessage = memo(
wrapCodeBlocksWithoutVisit,
]}
>
- {text}
+ {preprocessMarkdown(text)}
>
)
diff --git a/web/screens/Thread/ThreadCenterPanel/TextMessage/index.tsx b/web/screens/Thread/ThreadCenterPanel/TextMessage/index.tsx
index c029da74d7..777b9436de 100644
--- a/web/screens/Thread/ThreadCenterPanel/TextMessage/index.tsx
+++ b/web/screens/Thread/ThreadCenterPanel/TextMessage/index.tsx
@@ -141,7 +141,11 @@ const MessageContainer: React.FC<
)}
dir="ltr"
>
-
+
)}
>