I have some text that I have inputted into a "dangerouslySetInnerHTML" to display appropriate formatting. The formatting includes line breaks, bold tags and hyperlinks.
I want a user to be able to copy from clipboard while preserving the formatting of the template.
I managed to copy from clipboard but the copied text includes the raw html and not the formatting.
Ex.
const myTemplate = <p>Hello <a href="${link}">User</a></p>
//Template
<Dialog
isShown={showDialog}
onCloseComplete={() => setShowDialog(false)}
topOffset={4}
footer={
<Button onClick={() => navigator.clipboard.writeText(
document?.getElementById('to-copy')?.innerHTML,
)
}
>
Click here to copy the template
</Button>
<div id="to-copy" dangerouslySetInnerHTML={{ __html: `${myTemplate}` }}></div>
Desired Output:
Hello User(hyperlink)