Copy codeblock contents to clipboard

AI-generated summary

Discourse has introduced a new feature allowing users to copy codeblock contents via a copy button, now enabled by default. This feature applies to pre > code blocks but not inline, quoted, or oneboxed codeblocks, and is incompatible with Internet Explorer due to its end of support. The Copy Codeblocks Theme Component remains available for older instances but is no longer updated. Initially, the feature was off by default, but it has since been enabled by default and moved to a hidden site setting. Users who previously disabled the setting may need to use SiteSetting.show_copy_button_on_codeblocks=true in Rails to re-enable it justin, JammyDodger, Don.

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

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:

44 Likes

Just a little extra announcement to append to this…

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

8 Likes

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.

5 Likes

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