Skip to content

Allow copying recipe link with name as rich text #31

@jg10-mastodon-social

Description

@jg10-mastodon-social

Apparently since 2024 there is now widespread support for writing HTML to the clipboard.
https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/write

This would allow the share recipe modal to transparently copy both plain text and HTML versions of a link, and if it supports HTML, the receiving application could display the link using it's human readable name.

It seems the key code to modify would be

await navigator.clipboard.writeText(text);

The new code would do something like:

try {
  const html = `<a href="${url}">${text}</a>`;
  await navigator.clipboard.write([
     new ClipboardItem({
       "text/plain": new Blob([url], { type: "text/plain" }),
       "text/html": new Blob([html], { type: "text/html" })
     })
  ]);
} catch (err) {
  await navigator.clipboard.writeText(url);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions