How to use copy-to-clipboard with pre-formatted text?

79 views
Skip to first unread message

Vincenzo Romano

unread,
Feb 19, 2020, 4:01:58 AM2/19/20
to TiddlyWiki
I am using tiddlywiki as an operation manual.
In a lor of places I have some pre-formatted text (either single string or block of text with one or three back quotes) to show commands to be executed on a terminal.
I would like to be able to copy those commands into the clipboard by using the copy-to-clipboard macro.
I haven't found a way and am not even sure this can be actually done.
Any hint?

BurningTreeC

unread,
Feb 19, 2020, 6:43:17 AM2/19/20
to TiddlyWiki
You can use the copy-to-clipboard macro right away

<<copy-to-clipboard """your text goes here""">>

PMario

unread,
Feb 19, 2020, 6:43:38 AM2/19/20
to TiddlyWiki
Hi,

You can download and drag and drop import the file. It contains 3 tiddlers.

 - cmd-code-macro-test
 - cmd-code-macro
 - $:/core/macros/copy-to-clipboard

At the moment the core copy-to-clipboard macro can't handle single backtick code eg: `cd c:\` so I needed to modify the core copy-to-clipboard macros.

cmd-code-macro contains

.code, .cmd and _cmd macros. The tiddler cmd-code-macro-test contains some examples, which you can see in edit-mode.

The whole thing is a bit hacky at the moment. So I may create a pull-request on github. But I'm not 100% sure how it can be improved and I don't have more time atm.

have fun!
mario


cmd-code-copy-to-clipboard.json

PMario

unread,
Feb 19, 2020, 6:48:29 AM2/19/20
to TiddlyWiki

TonyM

unread,
Feb 19, 2020, 10:48:00 PM2/19/20
to TiddlyWiki
You could build your own macro that you give your code snipits to as a parameter wrapped in triple quotes
<<yourmacro """
your code snipit hear
""">>

The in a tiddler tagged as a macro
\define yourmacro(code)
Display and provide copy to clipboard $code$ here
\end

The advantage being you can enhance your macro later without touching your doco just your macro.

Regards
Tony

Reply all
Reply to author
Forward
0 new messages