diff --git a/app/frontend/src/components/Answer/Answer.tsx b/app/frontend/src/components/Answer/Answer.tsx index e5619e0c33..75b0a03504 100644 --- a/app/frontend/src/components/Answer/Answer.tsx +++ b/app/frontend/src/components/Answer/Answer.tsx @@ -1,4 +1,4 @@ -import { useMemo } from "react"; +import { useMemo, useState } from "react"; import { Stack, IconButton } from "@fluentui/react"; import { useTranslation } from "react-i18next"; import DOMPurify from "dompurify"; @@ -46,6 +46,20 @@ export const Answer = ({ const parsedAnswer = useMemo(() => parseAnswerToHtml(answer, isStreaming, onCitationClicked), [answer]); const { t } = useTranslation(); const sanitizedAnswerHtml = DOMPurify.sanitize(parsedAnswer.answerHtml); + const [copied, setCopied] = useState(false); + + const handleCopy = () => { + // Single replace to remove all HTML tags to remove the citations + const textToCopy = sanitizedAnswerHtml.replace(/]*>\d+<\/sup><\/a>|<[^>]+>/g, ""); + + navigator.clipboard + .writeText(textToCopy) + .then(() => { + setCopied(true); + setTimeout(() => setCopied(false), 2000); + }) + .catch(err => console.error("Failed to copy text: ", err)); + }; return ( @@ -53,6 +67,13 @@ export const Answer = ({
+