Update to "Quick copy to clipboard" feature for Markdown content

Request Details

  1. Add a text field and set “Display as” to “Markdown”
  2. The field is now displayed to the end user with the Markdown formatting applied.
  3. Enable the “Quick copy to clipboard” toggle for the field

Current Behaviour
Clicking the copy button copies the raw field content, including the Markdown formatting

Requested Behaviour
Clicking the copy button copies the rich text of the field as it’s displayed. It can then be easily copied into other systems, for example posting on social media. This could be an option on the quick copy configuration.

async function copyToClip(elementId) {
    const rich = document.getElementById(elementId).innerHTML
    const plain = document.getElementById(elementId).innerText    
    if (typeof ClipboardItem !== "undefined") {
        const html = new Blob([rich], { type: "text/html" });
        const text = new Blob([plain], { type: "text/plain" });
        const data = new ClipboardItem({ "text/html": html, "text/plain": text });
        await navigator.clipboard.write([data]);
    } else {
        const cb = e => {
            e.clipboardData.setData("text/html", rich);
            e.clipboardData.setData("text/plain", plain);
            e.preventDefault();
        };
        document.addEventListener("copy", cb);
        document.execCommand("copy");
        document.removeEventListener("copy", cb);
    }
}
1 Like