In another thread I was contemplating building thumbnails representing all the palettes available. When I tried to address one of the limitations of my approach, I hit a wall: Is there a clean way to get a named color from a palette that is not the current one?
I thought it should be easy, until I realized that there is an odd sort of recursion going on in the current color retrieval process., one not trivial to override. I was wondering if anyone had a suggestion.
The current colour
macro looks like approximately like this:
\define colour(name)
<$transclude tiddler={{$:/palette}} index="$name$">
<$transclude tiddler="$:/palettes/Vanilla" index="$name$">
<$transclude tiddler="$:/config/DefaultColourMappings/$name$"/>
</$transclude>
</$transclude>
\end
(“Approximately” because I’ve added line-breaks and indentation for readability.)
And entries in the color palettes have one of three forms:
background: #ffffff
blockquote-bar: <<colour muted-foreground>>
button-background:
Either they are
- references to a CSS color value (e.g.
#ffffff
,#cfc
,rgb(51, 204, 153)
, orrgba(0, 200, 0, 0.7)
), or they are - recursive references to a different value (
<<color-muted-foreground>>
) - blank, like
button-background
above.
The trouble for me is that the data has the recursive calls built in. I can’t write a new function that does a different recursion on the same data, because it’s already too late. The recursive call has happened before I would get a chance to deal with it, and it’s been run on the current palette, not on the version I would like.
I had two failed attempts to solve this.
First, I thought I could wrap the body of my function in a <$let>
statement that set the palette to what I wanted and then reset it after I called <<colour>>
. Of course this fails; the coulour
macro isn’t using a variable to refer to the current palette but the text reference {{$:/palette}}
. It’s possible this technique could be resurrected by changing the text value of $:/palette
and then resetting afterward. I don’t really see how, as I believe this would have to be inside some user action to do this, but maybe I’m missing something. But even if I could, that would feel really wrong, to invoke a change in a fairly central tiddler just to temporarily use another value and set it back. It seems fraught.
Second, I thought I could manually do the same sort of things that the color macro is doing, by using the palette text like a data tiddler, and then manually adjusting any recursive calls to use my new version, keeping the CSS values, and for blank ones, hopping through the same Vanilla > config/DefaultColourMappings
hoops done in the <<colour>>
macro. I wasn’t sure I had the chops to do this all the way through, but I never got the chance because I was stopped up front by the simple fact that I can’t find a way to use a string as I would a data tiddler. Is that possible? I know I can do so with JSON strings. I can use jsonget
/jsonextract
to pull out values from a JSON-formatted string; can I do so with a data-tiddler formatted string (such as "a: 1\nb:2\nc:3"
)? Obviously, with a lot of work, I can recreate the whole data-tiddler handling bit for strings. But if I’m going to do that, then I will probably have to do that in JS, and not in wikitext, at least given my skill levels with TW and JS.
So that’s the question. Is there some simpler way to get the value of a named color from a palette that is not the current default one? Or can one of my two failed attempts be revived? Or should I – if I decide to pursue this – descend to JavaScript for this?