Right, I think I’ve found a way to do this — but using runCommand and sed, rather than internally in Tinderbox.
Just to pull it all together for anyone coming to the thread afresh, the aim is to produce a Table of Contents of a note’s children, in markdown, with each heading a clickable link (for which the markdown syntax is [Heading Name](#heading-name)
.
The problem is that the method used to collect the headings from the children always add " "
around the entries, because lists and sets always do that when ( )
are in a entry, and because replace() can’t deal with "
, you can’t post-process the output in Tinderbox to remove the them…
But, if we use the command line program ‘sed’ we can strip the "
from the elements.
Basically, we need
-
A user attribute
$SedCommand
with the valuesed 's/\"//g'
. (I’ve put it in a noteConfig
, so reference it with `$SedCommand(“Config”). -
A runCommand to apply SedCommand to the relevant set and remove the
"
into a string which can then be printed. The action code is:
Collect the names of the children and format them in a bullet point clickable list of headings:
^action($MySet=(collect(descendants(this),"[" + $Name+"](#" + $Name.lowercase.replace(" ","-") + ")")).unique.format("**TOC***\n","- ","\n",""))^
Echo the values of $MySet and $SedCommand into a single command run in the command line, and return the quote-less result back into $MyString:
^action($MyString=runCommand("echo '" + $MySet + "' | " + $SedCommand("Config")))^
Export the string in the normal way
^value($MyString)^
The result is:
**TOC**
- [Daily Notes](#daily-notes)
- [Markdown image links redux](#markdown-image-links-redux)
- [Playing with the grandkids](#playing-with-the-grandkids)
Hope this is useful for anyone else who wants to try something similar, and thanks to all on whose ideas this is built.