TiddlyWiki / TiddlyWiki5

A self-contained JavaScript wiki for the browser, Node.js, AWS Lambda etc.
https://tiddlywiki.com/
Other
7.99k stars 1.18k forks source link

[IDEA] Handle filter syntax in TOC exclude parameter #7239

Open ericshulman opened 1 year ago

ericshulman commented 1 year ago

Normally, the TOC code dynamically builds an "exclude" list containing tiddler titles that have already been "visited" in the current branch. This prevents infinite recursion when a "tag loop" occurs. However, it is also possible to pass in an initial list of titles to exclude by using:

<$macrocall $name="toc-selective-expandable" tag="SomeRootTag" exclude="Title1 Title2 ..." />

Recently, someone asked (https://talk.tiddlywiki.org/t/tw5-using-filter-notation-in-code-for-table-of-contents/6034) how to use a filter to exclude tiddlers that have a specific tag value (e.g., "[tag[Todo]]").

I provided a solution that first gets the list of all tiddlers with that tag, so that list can then be passed as the initial value of the exclude parameter:

<$set name="todo" filter="[tag[Todo]]">
<div class="tc-table-of-contents">
<$macrocall $name="toc-selective-expandable" tag="ML" sort="sort[created]" exclude=<<todo>> />
</div>
</$set>

This approach was necessary because internal to the TWCore TOC macro code, the list of excluded tiddler titles is handled using [enlist<__exclude__>] and -[enlist<__exclude__>].

If these code instances were changed to [subfilter<__exclude__>] and -[subfilter<__exclude__>], then the initial value of the exclude parameter could directly contain filter syntax, like this:

<div class="tc-table-of-contents">
<$macrocall $name="toc-selective-expandable" tag="ML" sort="sort[created]" exclude="[tag[Todo]]" />
</div>
pmario commented 1 year ago

If the exclude parameter could be a real filter, I think that would make sense and we could officially document it. At the moment it's not documented, because of the internal use of enlist.

If I remember it right, the subfilter operator was not available as we did rewrite the recursion protection.

pmario commented 9 months ago

@ericshulman -- This one should also be fixed. see: https://tiddlywiki.com/#Table-of-Contents%20Macros