Can I create a macro that pastes the content of all my code blocks to the clipboard while I click on them?

86 views
Skip to first unread message

Rafael Oliveira

unread,
Aug 4, 2020, 1:47:11 AM8/4/20
to tiddl...@googlegroups.com
Checking my browser inspector I've realized that all blocks of code on TW appear inside the HTML inside the code element... Considering that I can create a macro that runs on all tiddlers by tagging it to  $:/tags/ViewTemplate, can I identify this code element on currentTiddler just so I can get its content and paste it to the clipboard if I click on it?

PMario

unread,
Aug 4, 2020, 5:39:29 AM8/4/20
to TiddlyWiki

vincenz...@notorand.it

unread,
Jan 5, 2021, 9:58:19 AM1/5/21
to TiddlyWiki
How do I create that button on the top-right side of the code block so It copies the entire code block to clipboard?
It looks like I can edit the tiddlywiki.com website to make it look like what I want to get. But when I actually do it on my own file (v5.1.23), it doesn't work.
Any idea?

Mark S.

unread,
Jan 5, 2021, 10:29:56 AM1/5/21
to TiddlyWiki
Let's say your code block is in a tiddler "mycode"

Paste this into a tiddler, call it  and tag it with $:/tags/ViewTemplate

<$list filter="[all[current]prefix[mycode]]">
<$button>
<$macrocall $name="copy-to-clipboard" src={{mycode}}/>
</$button>
</$list>

Save, and clickon the tag $:/tags/ViewTemplate. Drag and drop "mytemplate" so it's just in front of the body tag. Now a button will appear on your mycode tiddler that will let you copy the code. Always make backups before trying changes like this.
Reply all
Reply to author
Forward
0 new messages