I did very little testing, so all corrections, enhancements, and other feedback are much appreciated!
Here’s an updated version that should correct the issue: Sample $docs.filters.tid (2.0 KB)
I’ll update the code in my previous post as well.
In addition to correcting to account for multi-word values (just a matter of adding quote marks around the parameter), I added a couple of additional lines to my .param-display
function:
\function .trim-label() [<.param-type>!match[string]] :then[<label>trim[]] ~[<label>]
\function .param-display()
[<.param-type>match[variable]then[<XX>]]
~[<.param-type>match[transclusion]then[{!!XX}]]
~"[XX]"
+[search-replace[XX],<.trim-label>]
:map[<.param-type>match[variable]then{!!title}search-replace:g[ ],[-]else{!!title}]
\end .param-display
- The final
:map
run replaces any spaces in the parameter with hyphens when displaying variable parameters. I didn’t make the same substitution for {!!field}
-type parameters since field names can theoretically include spaces, but we certainly could do so there as well.
-
.trim-label
removes any leading or trailing space from non-literal parameters — and here, I did trim
fields as well. You could have a field name with a trailing space, but IMO it’s asking for trouble, and not something we want to promote.
As a side note, I’m not entirely happy with my use of search-replace
to substitute the param name; I chose it primarily because it felt more efficient than using addprefix
and addsuffix
(which can also be problematic when used with brackets, particularly [
— which merely looks like a mistake — and ]
— which actually disrupts the filter parsing). If anyone has a more elegant solution, I’d love to hear it.
I’ll also note that while I do see the appeal of adding this extra functionality to all the sample filters, I really designed it while thinking of the syntax illustration “filters” currently used for filter operators like range
(https://tiddlywiki.com/#range%20Operator) and search-replace
(https://tiddlywiki.com/#search-replace%20Operator). The addprefix
tiddler doesn’t seem to have one at present (perhaps because it’s harder to abstract?), but if I were writing one, I might do something like
Cat Garden [[Favourite Armchair]] +[addprefix<prefix>]
or the following, in my proof-of-concept syntax:
<$docs.filters>
Cat Garden [«Favourite Armchair»] +[addprefix«prefix»]
</$docs.filters>