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:
- 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, this feature is not compatible with Internet Explorer.
- The Copy Codeblocks Theme Component will still exist for older Discourse instances but will not be receiving any more updates.