tip: copying chunks of code to clipboard

136 views
Skip to first unread message

Rustem

unread,
Aug 28, 2015, 10:11:33 PM8/28/15
to TiddlyWiki

I keep a TiddlyWiki for documenting bits of code, scripts etc. In TWC, I had a homegrown plugin that added a “Copy All to Clipboard” button to every code block. (Eventually, it degraded to “Select All”, when manipulating the clipboard from a web page became impossible, with tightened security in a newer version of Firefox.)

I was missing that functionality in TW5, but didn’t want to rewrite the plugin since I would not be able to make it copy to clipboard anyways. Finally, it occured to me that there might be a browser add-on that could do the same. All that is required is copy inner HTML from an element on a right click. It wasn’t easy to find, but there it is: https://addons.mozilla.org/en-US/firefox/addon/texttotag/

After installing it, right click on your piece of code, select “TextToTag” from the menu and voila - the code is in your clipboard.

When clicking, make sure you are pointing to the text, and not to the whitespace between the lines or on the right-hand side in a block of code. And if you find that limitation inconvenient, you can click anywhere within the block of code if you add this to your stylesheet:

pre code, pre.hljs code { display: table; }

Enjoy!

—R

BJ

unread,
Aug 29, 2015, 7:01:57 AM8/29/15
to TiddlyWiki
HI Rustem,
it is also possible to use tiddlyclip to copy hightlighted chuck of a web page as html and have them appear in a tiddler, just replace @text with @web in the snip rule:-

http://tiddlyclip.tiddlyspot.com#defaultSnip

cheers
BJ

Rustem

unread,
Aug 29, 2015, 1:34:05 PM8/29/15
to TiddlyWiki
BJ,

I think you misunderstood. I was describing a way to copy a fragment of code from a wiki to clipboard, for when you actually need to reuse it. The entire contents of a <code>...</code> tag, without having to drag your mouse across it to highlight everything. (If you want only a part of it, you'd still have to do the usual highlight+copy way.)

Rather than having a multitude of small scripts, I keep them in my wiki, commented and tagged, and just copy and paste them into command line when I need to run them.  I guess it's a somewhat specific use case, not everyone will find this useful enough to bother.

--R

BJ

unread,
Aug 30, 2015, 3:05:15 AM8/30/15
to TiddlyWiki
Ah - I did misunderstand. I used to use a firefox extension called 'terminalrun' (now defunct) that would automatically hightlight linux commands in all pages and you could run them by clicking on them (not very secure!)
Reply all
Reply to author
Forward
0 new messages