Tinderbox Training Video 31 - Integrating Export Code & Action Code in Your Text

Stupid me, .replace() was fine. I was escaping the wrong, being over focussed on parentheses. Consider:

.replace("{","(")

What’s wrong. We recall the first parameter is a regex. Doh, so both curly and straight brackets are characters with regex roles, so must be escaped, like so:

.replace("\{","(")

The second term is a literal string so the ( has no special meaning there). Thus my profuse apologies to @eastgate for a totally wrong call above.

As a result @brookter’s one-liner can be made to work with a bit of tweaking. First we work around collect() generating quotes in the output by using curly brackets instead of parentheses:

collect(descendants,"[" +$Name+"]{#"+$Name.lowercase.replace(" ","-")+"}").unique.format("","- ","\n","")

Then when the whole string is made, we replace the curly brackets with parentheses.

.replace("\{","(").replace("\}",")")

Here is the whole thing as a one liner. I’ve removed the redundant this reference and the extra parentheses enclosing collect :slight_smile:```
^value(collect(descendants,"[" +$Name+"]{#"+$Name.lowercase.replace(" “,”-")+"}").unique.format("","- “,”\n","").replace("{","(").replace("}",")"))^

Here is my earlier demo with the latter code as a new template 'md list3'. Try it out: [md-list2.tbx|attachment](upload://rgHVvVQoKWrCqEllyJPJJ6T8Nl8.tbx) (105.9 KB)
1 Like