This theme component is now deprecated in favor of Copy codeblock contents to clipboard, a core Discourse feature.
This theme component adds a copy button to codeblocks inside of Discourse posts -- perfect for communities sharing code samples or knowledge base articles that require copying text.
On desktop, the copy button shows up on hover over the block.
On mobile, the code button is shown always but pushes the code in the block down to avoid obfuscating the first line of code if too long.
Do note that this only works for codeblocks generated by `
\`, and not inline codeblocks.
This is a codeblock. Copy this text.
This is an
inline codeblock. Copy does not work here.
Big thanks to @joffreyjaffeux who did a major chunk of the initial development on this one.