I’m trying to copy rich text where the links from HTML elements are preserved but I can’t figure it out no matter how many times I try.
The code below is the best I can come up with, but it only copies text without preserving the links
const tempElem: HTMLDivElement = document.createElement("div");
tempElem.innerHTML = responseBody;
console.log("running clipboard.write()....");
try {
navigator.clipboard.write([
new ClipboardItem({
"text/html": new Blob([tempElem.innerText], {
type: "text/html",
}),
"text/plain": new Blob([tempElem.innerText], {
type: "text/plain",
}),
}),
])
console.log("Rich text copied to clipboard");
} catch (err) {
console.error("Failed to copy: ", err);
}