balibabu
commited on
Commit
·
30090ae
1
Parent(s):
63cb972
Fix: Answers with links to information not parsing #3839 (#3968)
Browse files### 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)
web/reducer.js
DELETED
@@ -1,26 +0,0 @@
|
|
1 |
-
import React, { useReducer } from 'react';
|
2 |
-
const CHANGE_LOCALE = 'CHANGE_LOCALE';
|
3 |
-
|
4 |
-
const mainContext = React.createContext();
|
5 |
-
|
6 |
-
const reducer = (state, action) => {
|
7 |
-
switch (action.type) {
|
8 |
-
case CHANGE_LOCALE:
|
9 |
-
return { ...state, locale: action.locale || 'zh' };
|
10 |
-
default:
|
11 |
-
return state;
|
12 |
-
}
|
13 |
-
};
|
14 |
-
|
15 |
-
const ContextProvider = (props) => {
|
16 |
-
const [state, dispatch] = useReducer(reducer, {
|
17 |
-
locale: 'zh',
|
18 |
-
});
|
19 |
-
return (
|
20 |
-
<mainContext.Provider value={{ state, dispatch }}>
|
21 |
-
{props.children}
|
22 |
-
</mainContext.Provider>
|
23 |
-
);
|
24 |
-
};
|
25 |
-
|
26 |
-
export { ContextProvider, mainContext, reducer };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
web/src/pages/chat/markdown-content/index.tsx
CHANGED
@@ -20,9 +20,10 @@ import { useTranslation } from 'react-i18next';
|
|
20 |
|
21 |
import 'katex/dist/katex.min.css'; // `rehype-katex` does not import the CSS for you
|
22 |
|
|
|
23 |
import styles from './index.less';
|
24 |
|
25 |
-
const reg = /(#{2}\d
|
26 |
const curReg = /(~{2}\d+\${2})/g;
|
27 |
|
28 |
const getChunkIndex = (match: string) => Number(match.slice(2, -2));
|
@@ -156,7 +157,9 @@ const MarkdownContent = ({
|
|
156 |
|
157 |
const renderReference = useCallback(
|
158 |
(text: string) => {
|
159 |
-
|
|
|
|
|
160 |
const chunkIndex = getChunkIndex(match);
|
161 |
return (
|
162 |
<Popover content={getPopoverContent(chunkIndex)} key={i}>
|
|
|
20 |
|
21 |
import 'katex/dist/katex.min.css'; // `rehype-katex` does not import the CSS for you
|
22 |
|
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));
|
|
|
157 |
|
158 |
const renderReference = useCallback(
|
159 |
(text: string) => {
|
160 |
+
const nextText = replaceTextByOldReg(text);
|
161 |
+
|
162 |
+
let replacedText = reactStringReplace(nextText, reg, (match, i) => {
|
163 |
const chunkIndex = getChunkIndex(match);
|
164 |
return (
|
165 |
<Popover content={getPopoverContent(chunkIndex)} key={i}>
|
web/src/pages/chat/utils.ts
CHANGED
@@ -41,3 +41,11 @@ export const buildMessageItemReference = (
|
|
41 |
|
42 |
return reference ?? { doc_aggs: [], chunks: [], total: 0 };
|
43 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
return reference ?? { doc_aggs: [], chunks: [], total: 0 };
|
43 |
};
|
44 |
+
|
45 |
+
const oldReg = /(#{2}\d+\${2})/g;
|
46 |
+
|
47 |
+
export const replaceTextByOldReg = (text: string) => {
|
48 |
+
return text.replace(oldReg, function (substring) {
|
49 |
+
return `${substring.slice(0, -2)}@@`;
|
50 |
+
});
|
51 |
+
};
|