Skip to content

Feature idea: copyable code #1380

@giltho

Description

@giltho

It would be helpful for code blocks to be copyable using a button. Stripe does this nicely with a clipboard button in the corner.

In js, this is not very difficult to achieve, it's something like:

// Get text without syntax-highlighting tags
const plainText = codeblock.innerText;
navigator.clipboard.writeText(plainText).then(() => {
  // Do something appropriate to confirm stuff has been copied
  console.log('Code copied!');
}).catch(err => {
  console.error('Failed to copy:', err);
});

PS: Sorry for the many opened issues, I just thought I'd a braindump of what I think would be nice after working on some documentation for a while :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions