Filter table of contents recursively

74 views
Skip to first unread message

Jon Dyer

unread,
Nov 3, 2020, 12:06:25 AM11/3/20
to tiddl...@googlegroups.com
At this link there are basic instructions for changing the sort order of the table of contents using the toc macro: https://tiddlywiki.com/#How%20to%20change%20the%20sort%20order%20of%20sub-branches%20in%20a%20TOC%20macro (also see https://tiddlywiki.com/#Table-of-Contents%20Macros). I would like to have more control over how the actual tagging/filtering is done. Specifically, I would like to recursively apply a filter so that any list items that are tagged with a sub-category are excluded from the parent category, even if they are also tagged with the parent category.

Let me illustrate. I got it to work using the list field in the parent category with the list-links macro like so:

<<list-links "[tag<currentTiddler>] -[{!!list}split[ ]tagging[]]">>

with a list field like this:
Subcategory1 Subcategory2


But try as I might I can't get a similar thing to work in the Table of Contents. Things like the following don't work:
<div class="tc-table-of-contents">
<<toc-selective-expandable tag:"Contents" exclude:"[{!!list}split[ ]tagging[]]" >>
</div>


Or hacks like this:
<div class="tc-table-of-contents">
<<toc-selective-expandable tag:"Contents" sort:"[{!!list}split[ ]tagging[]" >>
</div>


I've spent too many hours on this now (not wasted though! I've learned much about filters in TW). Any tips on how to achieve what I want? I'm sure there's a clever set of filters that I just can't quite get right. I'm also not afraid to edit the core toc macro if needs be. Thanks!

Jon Dyer

unread,
Nov 3, 2020, 5:40:35 PM11/3/20
to TiddlyWiki
I guess I should be clearer about the structure I'm looking at here:
  • Root
    • Parent
      • Child1
      • Child2
        • Child21
        • Child22
        • Child23
Suppose that each of (Child21, Child22, Child23) are all tagged with "Parent", in addition to being tagged with "Child2" (so they fit there under the hierarchy). I don't want those three grandchildren to also show up directly under "Parent". Does that make sense?

Jon Dyer

unread,
Nov 3, 2020, 5:45:39 PM11/3/20
to TiddlyWiki
I think probably https://wikilabs.github.io/editions/tocP/ is the best solution for me now.
Reply all
Reply to author
Forward
0 new messages