TiddlyWiki / TiddlyWiki5

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

[BUG] toc-tabbed-* macros should accept initial `exclude` parameter #7261

Open ericshulman opened 1 year ago

ericshulman commented 1 year ago

Describe the bug

Internally, the toc-* macros use an exclude parameter to automatically "prune" the branches of the tree to prevent infinite "tag loops" by not showing links to tiddlers that have already been listed as a parent tiddler in the current branch of the tree. For most toc-* macros, the exclude parameter can also be passed in with an initial list of tiddler titles. This allows the specified titles to be explicitly bypassed when showing the resultant tree. However, the toc-tabbed-internal-nav and toc-tabbed-external-nav macros do not support passing in an initial value for this parameter, preventing its use as a "bypass" for specific titles.

To correct this, some minor additions to the existing toc-tabbed-internal-nav and toc-tabbed-external-nav macro definitions are needed in $:/core/macros/toc:

First , in toc-tabbed-internal-nav, add exclude as a parameter and pass the parameter value along in the $macrocall to toc-tabbed-external-nav:

\define toc-tabbed-internal-nav(tag,sort:"",selectedTiddler:"$:/temp/toc/selectedTiddler",unselectedText,
   missingText,template:"",exclude)
...
  <$macrocall $name="toc-tabbed-external-nav" tag=<<__tag__>> sort=<<__sort__>>
    selectedTiddler=<<__selectedTiddler__>> unselectedText=<<__unselectedText__>>
    missingText=<<__missingText__>> template=<<__template__>> exclude=<<__exclude__>>/>
...

Then, in toc-tabbed-external-nav, add exclude as a parameter and pass the parameter value along in the $macrocall to toc-selective-expandable:

\define toc-tabbed-external-nav(tag,sort:"",selectedTiddler:"$:/temp/toc/selectedTiddler",unselectedText,
   missingText,template:"",exclude)
...
<$macrocall $name="toc-selective-expandable" tag=<<__tag__>> sort=<<__sort__>>
   itemClassFilter="[all[current]] -[<__selectedTiddler__>get[text]]" exclude=<<__exclude__>>/>
...

With these minor additions in place, it will then be possible to exclude specific titles. For example, to exclude the "HelloThere" branch from the TableOfContents at https://TiddlyWiki.com, you can write:

<div class="tc-table-of-contents">
<$macrocall $name="toc-tabbed-internal-nav" tag="TableOfContents" sort="sort[created]" exclude="HelloThere" />
</div>

or, to exclude the "example" tiddlers (i.e., in the Reference > Filters > Filter Operators branch):

<$set name=examples filter="[suffix[(Examples)]]">
<div class="tc-table-of-contents">
<$macrocall $name="toc-tabbed-internal-nav" tag="TableOfContents" sort="sort[created]" exclude=<<examples>> />
</div>
</$set>

Note that, in combination with https://github.com/Jermolene/TiddlyWiki5/issues/7239 (which enables passing of filter syntax directly in the exclude parameter), we could simplify the above to:

<div class="tc-table-of-contents">
<$macrocall $name="toc-tabbed-internal-nav" tag="TableOfContents" sort="sort[created]" exclude="[suffix[(Examples)]]" />
</div>
pmario commented 1 year ago

Note that, in combination with https://github.com/Jermolene/TiddlyWiki5/issues/7239 (which enables passing of filter syntax directly in the exclude parameter), we could simplify the above to:

Yes. I think those 2 should go together, then we can officially document the "exclude" parameter. Till no it is kind of a hack.

Jermolene commented 1 year ago

Thanks @ericshulman

Would anyone like to make a PR for these changes?

pmario commented 11 months ago

@ericshulman -- I think we can close this one. Features have been merged for v5.3.0