From b287aaccecfa8a283a94d9bda4bb3b2f9b1fe524 Mon Sep 17 00:00:00 2001 From: sayThQ199 <693858278@qq.com> Date: Thu, 17 Apr 2025 19:50:41 +0800 Subject: [PATCH] fix: Correctly render multiple think blocks in Markdown (#18310) Co-authored-by: xzj16125 Co-authored-by: crazywoola <427733928@qq.com> --- web/app/components/base/markdown.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/web/app/components/base/markdown.tsx b/web/app/components/base/markdown.tsx index 24ae59af73..d50c397177 100644 --- a/web/app/components/base/markdown.tsx +++ b/web/app/components/base/markdown.tsx @@ -85,9 +85,11 @@ const preprocessLaTeX = (content: string) => { } const preprocessThinkTag = (content: string) => { + const thinkOpenTagRegex = /\n/g + const thinkCloseTagRegex = /\n<\/think>/g return flow([ - (str: string) => str.replace('\n', '
\n'), - (str: string) => str.replace('\n', '\n[ENDTHINKFLAG]
'), + (str: string) => str.replace(thinkOpenTagRegex, '
\n'), + (str: string) => str.replace(thinkCloseTagRegex, '\n[ENDTHINKFLAG]
'), ])(content) }