diff --git a/frontend/src/components/ChatBubble/index.jsx b/frontend/src/components/ChatBubble/index.jsx index 4ffc3d085ea..7b37cd5d17e 100644 --- a/frontend/src/components/ChatBubble/index.jsx +++ b/frontend/src/components/ChatBubble/index.jsx @@ -1,6 +1,8 @@ import React from "react"; import UserIcon from "../UserIcon"; import { userFromStorage } from "@/utils/request"; +import renderMarkdown from "@/utils/chat/markdown"; +import DOMPurify from "@/utils/chat/purify"; export default function ChatBubble({ message, type, popMsg }) { const isUser = type === "user"; @@ -16,11 +18,12 @@ export default function ChatBubble({ message, type, popMsg }) { role={type} /> - - {message} - +
diff --git a/frontend/src/components/EditingChatBubble/index.jsx b/frontend/src/components/EditingChatBubble/index.jsx index feabd4c6ee1..652297c7914 100644 --- a/frontend/src/components/EditingChatBubble/index.jsx +++ b/frontend/src/components/EditingChatBubble/index.jsx @@ -1,6 +1,8 @@ import React, { useState } from "react"; import { X } from "@phosphor-icons/react"; import { useTranslation } from "react-i18next"; +import renderMarkdown from "@/utils/chat/markdown"; +import DOMPurify from "@/utils/chat/purify"; export default function EditingChatBubble({ message, @@ -57,9 +59,12 @@ export default function EditingChatBubble({ /> ) : ( tempMessage && ( -- {tempMessage} -
+ ) )} diff --git a/frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/HistoricalMessage/index.jsx b/frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/HistoricalMessage/index.jsx index a5d60db4e07..5a5454bb283 100644 --- a/frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/HistoricalMessage/index.jsx +++ b/frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/HistoricalMessage/index.jsx @@ -6,7 +6,7 @@ import renderMarkdown from "@/utils/chat/markdown"; import { userFromStorage } from "@/utils/request"; import Citations from "../Citation"; import { v4 } from "uuid"; -import createDOMPurify from "dompurify"; +import DOMPurify from "@/utils/chat/purify"; import { EditMessageForm, useEditMessage } from "./Actions/EditMessage"; import { useWatchDeleteMessage } from "./Actions/DeleteMessage"; import TTSMessage from "./Actions/TTSButton"; @@ -17,11 +17,6 @@ import { ThoughtChainComponent, } from "../ThoughtContainer"; -const DOMPurify = createDOMPurify(window); -DOMPurify.setConfig({ - ADD_ATTR: ["target", "rel"], -}); - const HistoricalMessage = ({ uuid = v4(), message, diff --git a/frontend/src/utils/chat/purify.js b/frontend/src/utils/chat/purify.js new file mode 100644 index 00000000000..a6cf8520660 --- /dev/null +++ b/frontend/src/utils/chat/purify.js @@ -0,0 +1,8 @@ +import createDOMPurify from "dompurify"; + +const DOMPurify = createDOMPurify(window); +DOMPurify.setConfig({ + ADD_ATTR: ["target", "rel"], +}); + +export default DOMPurify;