Wouldn't it be cool to right click anywhere in a code block and have the option "copy code block to clipboard"?
I now programmed this Greasemonkey script for Firefox to add a 'select code' text below every
pre tag. If clicked the tag content will be selected and the user can copy it using CTRL+C or similar.
It looks like this:
3Please make it work also with Chrome.– lockstepFeb 19, 2011 at 16:11
@lockstep: I will have a look on it Feb 19, 2011 at 19:10
I've linked to this answer on meta.gis.stackexchange.com/questions/483/…, where a similar question has come up. The script works there (and I suspect on all stackexchange sites) if you use
// @include http://*.stackexchange.com/*. Maybe you could incorporate that in the version hosted on your server?– JakeMay 29, 2011 at 20:47
@lockstep: Does it work with the current version of Chrome? May 18, 2012 at 8:42
@lockstep: It works now. But you need tempermonkey user script manager. Refer : How to make `select code` work with google chrome?– user11232Jan 19, 2013 at 13:47
@MartinScharrer -- this question has been cited in meta.tex.stackexchange.com/q/6183/579 but trying to connect to your link fails. can you do something about that, please? May 31, 2015 at 12:06
I have created another Greasemonkey (Firefox) / Tampermonkey (Chrome) script that use clipboard.js.
When you hover a code section (
<pre><code>) there is a small
</> sign that appears on the top right corner of the script. You click it and voilà !
The code is available on this Gist.
How to use it :
- Install Greasemonkey (Firefox) / Tampermonkey (Chrome) for your browser.
- Read the code in the Gist (if you do not understand some code, do not install it) ! Click on the raw version of the gist.
- Install it.
Edit : I have created a second version. In the first version the button is not visible if the code is scrolled down. In the second version it stays visible ... and it has a different appearance (more
\tex one ;)).
<pre class="lang-tex prettyprint">Now if I could strip out all the HTML tags, I would have my code block. This is probably a long way round, but does this not show this is possible?