balibabu
commited on
Commit
·
28d7c08
1
Parent(s):
6f8784a
Fix: Fixed the issue where two consecutive indexes were displayed incorrectly #3839 (#3988)
Browse files### 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
CHANGED
@@ -23,7 +23,7 @@ import 'katex/dist/katex.min.css'; // `rehype-katex` does not import the CSS for
|
|
23 |
import { replaceTextByOldReg } from '../utils';
|
24 |
import styles from './index.less';
|
25 |
|
26 |
-
const reg = /(
|
27 |
const curReg = /(~{2}\d+\${2})/g;
|
28 |
|
29 |
const getChunkIndex = (match: string) => Number(match.slice(2, -2));
|
@@ -47,7 +47,8 @@ const MarkdownContent = ({
|
|
47 |
if (text === '') {
|
48 |
text = t('chat.searching');
|
49 |
}
|
50 |
-
|
|
|
51 |
}, [content, loading, t]);
|
52 |
|
53 |
useEffect(() => {
|
@@ -157,9 +158,7 @@ const MarkdownContent = ({
|
|
157 |
|
158 |
const renderReference = useCallback(
|
159 |
(text: string) => {
|
160 |
-
|
161 |
-
|
162 |
-
let replacedText = reactStringReplace(nextText, reg, (match, i) => {
|
163 |
const chunkIndex = getChunkIndex(match);
|
164 |
return (
|
165 |
<Popover content={getPopoverContent(chunkIndex)} key={i}>
|
|
|
23 |
import { replaceTextByOldReg } from '../utils';
|
24 |
import styles from './index.less';
|
25 |
|
26 |
+
const reg = /(~{2}\d+={2})/g;
|
27 |
const curReg = /(~{2}\d+\${2})/g;
|
28 |
|
29 |
const getChunkIndex = (match: string) => Number(match.slice(2, -2));
|
|
|
47 |
if (text === '') {
|
48 |
text = t('chat.searching');
|
49 |
}
|
50 |
+
const nextText = replaceTextByOldReg(text);
|
51 |
+
return loading ? nextText?.concat('~~2$$') : nextText;
|
52 |
}, [content, loading, t]);
|
53 |
|
54 |
useEffect(() => {
|
|
|
158 |
|
159 |
const renderReference = useCallback(
|
160 |
(text: string) => {
|
161 |
+
let replacedText = reactStringReplace(text, reg, (match, i) => {
|
|
|
|
|
162 |
const chunkIndex = getChunkIndex(match);
|
163 |
return (
|
164 |
<Popover content={getPopoverContent(chunkIndex)} key={i}>
|
web/src/pages/chat/utils.ts
CHANGED
@@ -44,8 +44,9 @@ export const buildMessageItemReference = (
|
|
44 |
|
45 |
const oldReg = /(#{2}\d+\${2})/g;
|
46 |
|
|
|
47 |
export const replaceTextByOldReg = (text: string) => {
|
48 |
return text.replace(oldReg, function (substring) {
|
49 |
-
return
|
50 |
});
|
51 |
};
|
|
|
44 |
|
45 |
const oldReg = /(#{2}\d+\${2})/g;
|
46 |
|
47 |
+
// To be compatible with the old index matching mode
|
48 |
export const replaceTextByOldReg = (text: string) => {
|
49 |
return text.replace(oldReg, function (substring) {
|
50 |
+
return `~~${substring.slice(2, -2)}==`;
|
51 |
});
|
52 |
};
|