From 409acf0d9fb4d47fdfb81437f1028ae36ea4c968 Mon Sep 17 00:00:00 2001 From: balibabu Date: Wed, 11 Dec 2024 16:29:17 +0800 Subject: [PATCH] Fix: Fixed the issue where two consecutive indexes were displayed incorrectly #3839 (#3988) ### What problem does this PR solve? Fix: Fixed the issue where two consecutive indexes were displayed incorrectly #3839 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- web/src/pages/chat/markdown-content/index.tsx | 9 ++++----- web/src/pages/chat/utils.ts | 3 ++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/web/src/pages/chat/markdown-content/index.tsx b/web/src/pages/chat/markdown-content/index.tsx index d4acf95e6..b265656fd 100644 --- a/web/src/pages/chat/markdown-content/index.tsx +++ b/web/src/pages/chat/markdown-content/index.tsx @@ -23,7 +23,7 @@ import 'katex/dist/katex.min.css'; // `rehype-katex` does not import the CSS for import { replaceTextByOldReg } from '../utils'; import styles from './index.less'; -const reg = /(#{2}\d+@{2})/g; +const reg = /(~{2}\d+={2})/g; const curReg = /(~{2}\d+\${2})/g; const getChunkIndex = (match: string) => Number(match.slice(2, -2)); @@ -47,7 +47,8 @@ const MarkdownContent = ({ if (text === '') { text = t('chat.searching'); } - return loading ? text?.concat('~~2$$') : text; + const nextText = replaceTextByOldReg(text); + return loading ? nextText?.concat('~~2$$') : nextText; }, [content, loading, t]); useEffect(() => { @@ -157,9 +158,7 @@ const MarkdownContent = ({ const renderReference = useCallback( (text: string) => { - const nextText = replaceTextByOldReg(text); - - let replacedText = reactStringReplace(nextText, reg, (match, i) => { + let replacedText = reactStringReplace(text, reg, (match, i) => { const chunkIndex = getChunkIndex(match); return ( diff --git a/web/src/pages/chat/utils.ts b/web/src/pages/chat/utils.ts index 3c8bef706..53887c798 100644 --- a/web/src/pages/chat/utils.ts +++ b/web/src/pages/chat/utils.ts @@ -44,8 +44,9 @@ export const buildMessageItemReference = ( const oldReg = /(#{2}\d+\${2})/g; +// To be compatible with the old index matching mode export const replaceTextByOldReg = (text: string) => { return text.replace(oldReg, function (substring) { - return `${substring.slice(0, -2)}@@`; + return `~~${substring.slice(2, -2)}==`; }); };