Skip to content

Commit

Permalink
Fix: Fixed the issue where two consecutive indexes were displayed inc…
Browse files Browse the repository at this point in the history
…orrectly #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)
  • Loading branch information
cike8899 authored Dec 11, 2024
1 parent 74c6b21 commit 409acf0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
9 changes: 4 additions & 5 deletions web/src/pages/chat/markdown-content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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(() => {
Expand Down Expand Up @@ -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 (
<Popover content={getPopoverContent(chunkIndex)} key={i}>
Expand Down
3 changes: 2 additions & 1 deletion web/src/pages/chat/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}==`;
});
};

0 comments on commit 409acf0

Please sign in to comment.