Fix: Answers with links to information not parsing #3839 (#3968)

### What problem does this PR solve?

Fix: Answers with links to information not parsing #3839

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
balibabu 2024-12-10 18:58:06 +08:00 committed by GitHub
parent 9a6d976252
commit e0533f19e9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 28 deletions

View File

@ -1,26 +0,0 @@
import React, { useReducer } from 'react';
const CHANGE_LOCALE = 'CHANGE_LOCALE';
const mainContext = React.createContext();
const reducer = (state, action) => {
switch (action.type) {
case CHANGE_LOCALE:
return { ...state, locale: action.locale || 'zh' };
default:
return state;
}
};
const ContextProvider = (props) => {
const [state, dispatch] = useReducer(reducer, {
locale: 'zh',
});
return (
<mainContext.Provider value={{ state, dispatch }}>
{props.children}
</mainContext.Provider>
);
};
export { ContextProvider, mainContext, reducer };

View File

@ -20,9 +20,10 @@ import { useTranslation } from 'react-i18next';
import 'katex/dist/katex.min.css'; // `rehype-katex` does not import the CSS for you
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));
@ -156,7 +157,9 @@ const MarkdownContent = ({
const renderReference = useCallback(
(text: string) => {
let replacedText = reactStringReplace(text, reg, (match, i) => {
const nextText = replaceTextByOldReg(text);
let replacedText = reactStringReplace(nextText, reg, (match, i) => {
const chunkIndex = getChunkIndex(match);
return (
<Popover content={getPopoverContent(chunkIndex)} key={i}>

View File

@ -41,3 +41,11 @@ export const buildMessageItemReference = (
return reference ?? { doc_aggs: [], chunks: [], total: 0 };
};
const oldReg = /(#{2}\d+\${2})/g;
export const replaceTextByOldReg = (text: string) => {
return text.replace(oldReg, function (substring) {
return `${substring.slice(0, -2)}@@`;
});
};