Transclusions, macros, the editor toolbar and the native HTML colorpicker

Hello. I am trying to create a button for the text editor that includes a user-selected color in the style definition specified in the prefix parameter of the $action-sendmessage widget.

I’ve got a macro defined, but I can’t get the hang of how to include a transclusion of the tiddler that my color picker edit-text field is writing to. Here’s where I am:

\define bgcolor(hexcolor)
<span style='background: $hexcolor$'>
\end

<$edit-text tiddler="$:/config/ColourPicker/New" type="color" tag="input"/>


<$action-sendmessage
	$message="tm-edit-text-operation"
	$param="wrap-selection"
	prefix=<<bgcolor pink>>
	suffix="</span>"
/>

How do I replace “pink” with {{$:/config/ColourPicker/New}}? Or am I perhaps thinking of this the wrong way?

Try defining a variable that holds the value of the color and let the macro substitute it for you:


\define bgcolor()
<span style='background: $(hexcolor)$'>
\end

<$edit-text tiddler="$:/config/ColourPicker/New" type="color" tag="input"/>

<$let hexcolor={{$:/config/ColourPicker/New}}>
<$action-sendmessage
	$message="tm-edit-text-operation"
	$param="wrap-selection"
	prefix=<<bgcolor>>
	suffix="</span>"
/>
</$let>
1 Like