fix copy button to preserve XML

This commit is contained in:
Hannes Rudolph 2025-05-16 17:29:01 -06:00
parent 6e958df09e
commit 5403db241f

View file

@ -13,16 +13,17 @@ export const CopyButton = ({ itemTask }: CopyButtonProps) => {
const { isCopied, copy } = useClipboard()
const { t } = useAppTranslation()
const onCopy = useCallback(
(e: React.MouseEvent) => {
e.stopPropagation()
const tempDiv = document.createElement("div")
tempDiv.innerHTML = itemTask
const text = tempDiv.textContent || tempDiv.innerText || ""
!isCopied && copy(text)
},
[isCopied, copy, itemTask],
)
const onCopy = useCallback(
(e: React.MouseEvent) => {
e.stopPropagation()
const withoutHighlights = itemTask.replace(
/<span class="history-item-highlight">(.*?)<\/span>/g,
"$1",
)
!isCopied && copy(withoutHighlights)
},
[isCopied, copy, itemTask],
)
return (
<Button