mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-08-12 20:29:06 +08:00
### 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:
parent
9a6d976252
commit
e0533f19e9
@ -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 };
|
|
@ -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 'katex/dist/katex.min.css'; // `rehype-katex` does not import the CSS for you
|
||||||
|
|
||||||
|
import { replaceTextByOldReg } from '../utils';
|
||||||
import styles from './index.less';
|
import styles from './index.less';
|
||||||
|
|
||||||
const reg = /(#{2}\d+\${2})/g;
|
const reg = /(#{2}\d+@{2})/g;
|
||||||
const curReg = /(~{2}\d+\${2})/g;
|
const curReg = /(~{2}\d+\${2})/g;
|
||||||
|
|
||||||
const getChunkIndex = (match: string) => Number(match.slice(2, -2));
|
const getChunkIndex = (match: string) => Number(match.slice(2, -2));
|
||||||
@ -156,7 +157,9 @@ const MarkdownContent = ({
|
|||||||
|
|
||||||
const renderReference = useCallback(
|
const renderReference = useCallback(
|
||||||
(text: string) => {
|
(text: string) => {
|
||||||
let replacedText = reactStringReplace(text, reg, (match, i) => {
|
const nextText = replaceTextByOldReg(text);
|
||||||
|
|
||||||
|
let replacedText = reactStringReplace(nextText, reg, (match, i) => {
|
||||||
const chunkIndex = getChunkIndex(match);
|
const chunkIndex = getChunkIndex(match);
|
||||||
return (
|
return (
|
||||||
<Popover content={getPopoverContent(chunkIndex)} key={i}>
|
<Popover content={getPopoverContent(chunkIndex)} key={i}>
|
||||||
|
@ -41,3 +41,11 @@ export const buildMessageItemReference = (
|
|||||||
|
|
||||||
return reference ?? { doc_aggs: [], chunks: [], total: 0 };
|
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)}@@`;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user