# Copy codeblock contents to clipboard

**URL:** https://meta.discourse.org/t/copy-codeblock-contents-to-clipboard/148855
**Category:** Announcements
**Tags:** new-feature
**Created:** [April 22, 2020, 2:07pm UTC](https://meta.discourse.org/t/copy-codeblock-contents-to-clipboard/148855 "2020-04-22T14:07:58Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![justin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/justin/32/157614_2.png) [@justin](https://meta.discourse.org/u/justin)
#### Post date: [April 22, 2020, 2:07pm UTC](https://meta.discourse.org/t/copy-codeblock-contents-to-clipboard/148855/1 "2020-04-22T14:07:59Z")

</div>

> :mega: Now live in core Discourse is the ability to show a copy button for codeblocks!

```plaintext
import { createWidget } from 'discourse/widgets/widget';

createWidget('my-widget', {
  tagName: 'div.hello',

  html() {
    return "hello world";
  }
});

```

**This feature is off by default,** but if your community could benefit from it, you can turn it on by enabling the `show copy button on codeblocks` site setting.

Some notes about the feature:

- The button shows up on `pre > code` codeblocks, but not inline, quoted, or oneboxed codeblocks.
- Since [Discourse is ending support for Internet Explorer 11 (IE11) on June 1, 2020](https://meta.discourse.org/t/discourse-is-ending-support-for-internet-explorer-11-ie11-on-june-1-2020/137984), this feature is not compatible with Internet Explorer.
- The [Copy Codeblocks Theme Component](https://meta.discourse.org/t/copy-codeblocks-theme-component/147441) will still exist for older Discourse instances but will not be receiving any more updates.

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [October 13, 2023, 3:03pm UTC](https://meta.discourse.org/t/copy-codeblock-contents-to-clipboard/148855/6 "2023-10-13T15:03:26Z")

</div>

Just a little extra announcement to append to this…

> [@justin](#):
>
> **This feature is off by default,** but if your community could benefit from it, you can turn it on by enabling the `show copy button on codeblocks` site setting.

The setting has proved to be so useful and universally lauded that it is now not only **default on** but also tucked away as a hidden site setting: :partying_face:

[https://github.com/discourse/discourse/commit/81f3f56deb9d9f363e8b3bdcf81306fc34751d7d](https://github.com/discourse/discourse/commit/81f3f56deb9d9f363e8b3bdcf81306fc34751d7d)

---

<div class="post-metadata">

### Author: ![Don](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/don/32/228726_2.png) [@Don](https://meta.discourse.org/u/Don)
#### Post date: [October 27, 2023, 5:12am UTC](https://meta.discourse.org/t/copy-codeblock-contents-to-clipboard/148855/7 "2023-10-27T05:12:32Z")

</div>

Hello :wave:

Just a little note… Previously it was enabled on my site but than I disabled it. Now I looked for the site setting `show_copy_button_on_codeblocks` to turn it on again. But it has been hidden. So the reason I write it is it seems if previously had disabled this setting it keeps the `default: false` status and can only be activate with rails `SiteSetting.show_copy_button_on_codeblocks=true`.

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [November 25, 2023, 9:54am UTC](https://meta.discourse.org/t/copy-codeblock-contents-to-clipboard/148855/8 "2023-11-25T09:54:14Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
