fix: safari reg error

This commit is contained in:
archer
2023-05-16 14:25:51 +08:00
parent 371e0e36c6
commit 021add2af4
4 changed files with 14 additions and 4 deletions

View File

@@ -13,12 +13,20 @@ import 'katex/dist/katex.min.css';
import styles from './index.module.scss';
import { codeLight } from './codeLight';
const Markdown = ({ source, isChatting = false }: { source: string; isChatting?: boolean }) => {
const Markdown = ({
source,
isChatting = false,
formatLink
}: {
source: string;
formatLink?: boolean;
isChatting?: boolean;
}) => {
const { copyData } = useCopyData();
const formatSource = useMemo(() => {
return formatLinkTextToHtml(source);
}, [source]);
return formatLink ? formatLinkTextToHtml(source) : source;
}, [source, formatLink]);
return (
<ReactMarkdown

View File

@@ -826,6 +826,7 @@ const Chat = ({
<Markdown
source={item.value}
isChatting={isChatting && index === chatData.history.length - 1}
formatLink
/>
{item.systemPrompt && (
<Button

View File

@@ -716,6 +716,7 @@ const Chat = ({
<Markdown
source={item.value}
isChatting={isChatting && index === shareChatData.history.length - 1}
formatLink
/>
{item.systemPrompt && (
<Button

View File

@@ -117,6 +117,6 @@ export const voiceBroadcast = ({ text }: { text: string }) => {
export const formatLinkTextToHtml = (text: string) => {
const httpReg =
/(?<!\[.*\]\()((http|https|ftp):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?)(?![\)])/gi;
/(http|https|ftp):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?/gi;
return text.replace(httpReg, '<a href="$&" target="_blank">$&</a>');
};