From b68de0d69f97a1ad1fd65129242b65b693903f2b Mon Sep 17 00:00:00 2001 From: Mario Pietsch Date: Thu, 24 Oct 2024 18:39:18 +0200 Subject: [PATCH] Toc uses currentTiddler as "tag" default parameter if it is missing (#8291) * toc's use currentTiddler, if tag prameter is undefined * add currentTiddler info to toc documentation --- core/wiki/macros/toc.tid | 55 +++++++++++-------- .../tiddlers/macros/TableOfContentsMacro.tid | 24 +++++--- 2 files changed, 46 insertions(+), 33 deletions(-) diff --git a/core/wiki/macros/toc.tid b/core/wiki/macros/toc.tid index a3f5b002a..2bbc4f6fc 100644 --- a/core/wiki/macros/toc.tid +++ b/core/wiki/macros/toc.tid @@ -37,7 +37,10 @@ tags: $:/tags/Macro \end \define toc(tag,sort:"",itemClassFilter:"", exclude) -<$macrocall $name="toc-body" tag=<<__tag__>> sort=<<__sort__>> itemClassFilter=<<__itemClassFilter__>> exclude=<<__exclude__>>/> +\whitespace trim +<$let __tag__={{{ [<__tag__>is[blank]thenelse<__tag__>] }}} > + <$macrocall $name="toc-body" tag=<<__tag__>> sort=<<__sort__>> itemClassFilter=<<__itemClassFilter__>> exclude=<<__exclude__>>/> + \end \define toc-linked-expandable-body(tag,sort:"",itemClassFilter,exclude,path) @@ -99,7 +102,7 @@ tags: $:/tags/Macro \define toc-expandable(tag,sort:"",itemClassFilter:"",exclude,path) \whitespace trim -<$let tag=<<__tag__>> sort=<<__sort__>> itemClassFilter=<<__itemClassFilter__>> path={{{ [<__path__>addsuffix[/]addsuffix<__tag__>] }}}> +<$let __tag__={{{ [<__tag__>is[blank]thenelse<__tag__>] }}} tag=<<__tag__>> sort=<<__sort__>> itemClassFilter=<<__itemClassFilter__>> path={{{ [<__path__>addsuffix[/]addsuffix<__tag__>] }}}> <$set name="excluded" filter="[subfilter<__exclude__>] [<__tag__>]">
    <$list filter="""[all[shadows+tiddlers]tag<__tag__>!has[draft.of]$sort$] -[<__tag__>] -[subfilter<__exclude__>]"""> @@ -173,7 +176,7 @@ tags: $:/tags/Macro \define toc-selective-expandable(tag,sort:"",itemClassFilter,exclude,path) \whitespace trim -<$let tag=<<__tag__>> sort=<<__sort__>> itemClassFilter=<<__itemClassFilter__>> path={{{ [<__path__>addsuffix[/]addsuffix<__tag__>] }}}> +<$let __tag__={{{ [<__tag__>is[blank]thenelse<__tag__>] }}} tag=<<__tag__>> sort=<<__sort__>> itemClassFilter=<<__itemClassFilter__>> path={{{ [<__path__>addsuffix[/]addsuffix<__tag__>] }}}> <$set name="excluded" filter="[subfilter<__exclude__>] [<__tag__>]">
      <$list filter="""[all[shadows+tiddlers]tag<__tag__>!has[draft.of]$sort$] -[<__tag__>] -[subfilter<__exclude__>]"""> @@ -188,31 +191,35 @@ tags: $:/tags/Macro \define toc-tabbed-external-nav(tag,sort:"",selectedTiddler:"$:/temp/toc/selectedTiddler",unselectedText,missingText,template:"",exclude) \whitespace trim -<$tiddler tiddler={{{ [<__selectedTiddler__>get[text]] }}}> -
      - <$linkcatcher to=<<__selectedTiddler__>>> -
      - <$macrocall $name="toc-selective-expandable" tag=<<__tag__>> sort=<<__sort__>> itemClassFilter="[all[current]] -[<__selectedTiddler__>get[text]]" exclude=<<__exclude__>>/> +<$let __tag__={{{ [<__tag__>is[blank]thenelse<__tag__>] }}}> + <$tiddler tiddler={{{ [<__selectedTiddler__>get[text]] }}}> +
      + <$linkcatcher to=<<__selectedTiddler__>>> +
      + <$macrocall $name="toc-selective-expandable" tag=<<__tag__>> sort=<<__sort__>> itemClassFilter="[all[current]] -[<__selectedTiddler__>get[text]]" exclude=<<__exclude__>>/> +
      + +
      + <$reveal stateTitle=<<__selectedTiddler__>> type="nomatch" text=""> + <$transclude mode="block" tiddler=<<__template__>>> +

      <>

      + <$transclude mode="block">$missingText$ + + + <$reveal stateTitle=<<__selectedTiddler__>> type="match" text=""> + $unselectedText$ +
      - -
      - <$reveal stateTitle=<<__selectedTiddler__>> type="nomatch" text=""> - <$transclude mode="block" tiddler=<<__template__>>> -

      <>

      - <$transclude mode="block">$missingText$ - - - <$reveal stateTitle=<<__selectedTiddler__>> type="match" text=""> - $unselectedText$ -
      -
      - + + \end \define toc-tabbed-internal-nav(tag,sort:"",selectedTiddler:"$:/temp/toc/selectedTiddler",unselectedText,missingText,template:"",exclude) \whitespace trim -<$linkcatcher to=<<__selectedTiddler__>>> - <$macrocall $name="toc-tabbed-external-nav" tag=<<__tag__>> sort=<<__sort__>> selectedTiddler=<<__selectedTiddler__>> unselectedText=<<__unselectedText__>> missingText=<<__missingText__>> template=<<__template__>> exclude=<<__exclude__>> /> - +<$let __tag__={{{ [<__tag__>is[blank]thenelse<__tag__>] }}}> + <$linkcatcher to=<<__selectedTiddler__>>> + <$macrocall $name="toc-tabbed-external-nav" tag=<<__tag__>> sort=<<__sort__>> selectedTiddler=<<__selectedTiddler__>> unselectedText=<<__unselectedText__>> missingText=<<__missingText__>> template=<<__template__>> exclude=<<__exclude__>> /> + + \end diff --git a/editions/tw5.com/tiddlers/macros/TableOfContentsMacro.tid b/editions/tw5.com/tiddlers/macros/TableOfContentsMacro.tid index 54343bf32..f21b08c94 100644 --- a/editions/tw5.com/tiddlers/macros/TableOfContentsMacro.tid +++ b/editions/tw5.com/tiddlers/macros/TableOfContentsMacro.tid @@ -1,27 +1,31 @@ created: 20140919155729620 -modified: 20230427125500432 +modified: 20240624102502089 tags: Macros [[Core Macros]] title: Table-of-Contents Macros type: text/vnd.tiddlywiki ~TiddlyWiki provides several macros for generating a tree of tiddler links by analysing [[tags|Tagging]]: -;<<.var toc>> +; <<.var toc>> : A simple tree -;<<.var toc-expandable>> + +; <<.var toc-expandable>> : A tree in which all the branches can be expanded and collapsed -;<<.var toc-selective-expandable>> + +; <<.var toc-selective-expandable>> : A tree in which the non-empty branches can be expanded and collapsed -;<<.var toc-tabbed-internal-nav>> and <<.var toc-tabbed-external-nav>> + +; <<.var toc-tabbed-internal-nav>> and <<.var toc-tabbed-external-nav>> : A two-panel browser: :* on the left, a selectively expandable tree that behaves like a set of vertical tabs :* on the right, the content of whichever tiddler the user selects in the tree The difference between the last two has to do with what happens when the user clicks a link in the right-hand panel: -;<<.var toc-tabbed-internal-nav>> +; <<.var toc-tabbed-internal-nav>> : The target tiddler appears in the right-hand panel, replacing the tiddler that contained the link -;<<.var toc-tabbed-external-nav>> + +; <<.var toc-tabbed-external-nav>> : The target tiddler appears in the normal way (which depends on the user's configured storyview) !! Structure @@ -42,9 +46,11 @@ To make a table of contents appear in the sidebar, see [[How to add a new tab to !! Parameters -;tag +; tag : The root tag that identifies the top level of the tree -;sort +: <<.from-version "5.3.5">> If the <<.param tag>> parameter is "missing" or "an empty" string, the <<.var curretTiddler>> variable is used + +; sort : An optional extra [[filter step|Filter Step]], e.g. `sort[title]` These two parameters are combined into a single [[filter expression|Filter Expression]] like this: