Store Result of a Procedure or Macro in a Variable

I like to store the output of a procedure or a macro into a variable. The purpose here is to use the contrastcolour macro.

\procedure foregroundColor()
 <$transclude $variable="contrastcolour"
              target=<<colour>> fallbackTarget=<<fallbackTarget>>
              colourA=<<colourA>> colourB=<<colourB>> />
\end foregroundColor

\procedure tag-pill-style(colour)
<$let
      backgroundColor=<<colour>>
      fallbackTarget={{$palette$##tag-background}}
      colourA={{$palette$##foreground}}
      colourB={{$palette$##background}}
 >

   background-color:<<backgroundColor>>;
   fill:rgb(<<foregroundColor>>);
   color:rgb(<<foregroundColor>>);
</$let>
\end tag-pill-style

Example

<$wikify name=nstyle text="""<<tag-pill-style black>>""" >
<div style=<<nstyle>> >
Hello My New Style
</div>
</$wikify>

This produces:

image.png

How can I remove $wikify and store the results in a variable?

I know the below scripts do not work.

<-- Does NOT Work -->

<div style=`${[<tag-pill-style black>]}$` >
Hello My New Style
</div>

<-- Does NOT Work -->

<div style={{{ [<tag-pill-style black>] }}} >
Hello My New Style
</div>

1 Like

If you can suggest an alternative that avoids the aforementioned procedures, please do so. At times, a completely different approach can yield the same result.

I thought it should be possible to create a global function, but I did not think any further.

Do you mean to replace the contrastcolour macro with a global function?

Just now I thought about a new filter operator contrastcolour[target],[fallbackTarget],[colourA],[colourB]. It should be possible to reuse the existing code.