Wouldn't it be cool to right click anywhere in a code block and have the option "copy code block to clipboard"?
2 Answers
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.
This is not a full solution yet (only work with Firefox) but could be expanded to all browsers and included in the site javascript files.
It looks like this:
-
3
-
-
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?– JakeCommented May 29, 2011 at 20:47 -
@lockstep: Does it work with the current version of Chrome?– Martin Scharrer ModCommented 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?– user11232Commented Jan 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? Commented 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 ;)).
-
-
I think yes : code indented by 4 spaces is wrapped in
<pre><code>
.– KpymCommented Dec 23, 2015 at 20:53
<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?