1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-08-07 22:33:50 +00:00

add new classes toc-item-included and toc-item-excluded, simplify code using more functions

This commit is contained in:
pmario 2024-02-04 06:15:49 +01:00
parent f3a314adf0
commit e1a42ebf82

View File

@ -3,20 +3,6 @@ tags: $:/tags/Macro
\whitespace trim \whitespace trim
<!-- v5.2.4 add "Custom Icons" -->
\procedure toc-open-icon() $:/core/images/down-arrow
\procedure toc-closed-icon() $:/core/images/right-arrow
<!-- v5.3.4 complete rewrite -->
\function tf.toc-stateTitle() [[$:/state/toc]] [<path>] "/" [<currentTiddler>] +[join[]]
\function tf.toc-newPath() [<path>addsuffix[/]addsuffix<tag>]
<!-- At the moment the following function is only used by "tabbed" tocs -->
\function tf.toc-getItemClass() [<selectedTiddler>get[text]match<currentTiddler>then[toc-item-selected]else[toc-item]]
\function tf.toc-includedClass() [tf.toc-getItemClass[]] [subfilter<tf.toc-include>match<currentTiddler>then[toc-item-included]] +[join[ ]]
\procedure toc-caption() \procedure toc-caption()
<span class="tc-toc-caption tc-tiny-gap-left"> <span class="tc-toc-caption tc-tiny-gap-left">
<$let name="tv-wikilinks" value="no"> <$let name="tv-wikilinks" value="no">
@ -27,22 +13,38 @@ tags: $:/tags/Macro
</span> </span>
\end \end
<!-- v5.2.4 add "Custom Icons" -->
\procedure toc-open-icon() $:/core/images/down-arrow
\procedure toc-closed-icon() $:/core/images/right-arrow
<!-- v5.3.4 complete rewrite -->
\function tf.toc-stateTitle() [[$:/state/toc]] [<path>] "/" [<currentTiddler>] +[join[]]
\function tf.toc-newPath() [<path>addsuffix[/]addsuffix<tag>]
<!-- At the moment the following function is only used by "tabbed" tocs -->
\function tf.toc-getItemClass() [<selectedTiddler>get[text]match<currentTiddler>then[toc-item-selected]else[toc-item]]
\function tf.toc-includedClass() [subfilter<tf.toc-include>match<currentTiddler>then[toc-item-included]]
\function tf.toc-itemClass() [<tf.toc-getItemClass>] [<tf.toc-includedClass>] [<tf.toc-exclude>!is[blank]then[toc-item-excluded]] +[join[ ]]
<!-- tf.toc-include needs to use <tag> --> <!-- tf.toc-include needs to use <tag> -->
\function tf.toc-include() [<tag>get[toc-include]] \function tf.toc-include() [<tag>get[toc-include]]
<!-- the following functions need to use <currentTiddler> --> <!-- the following 3 functions need to use <currentTiddler> -->
\function tf.toc-exclude() [<currentTiddler>get[toc-exclude]] \function tf.toc-getExclude() [<currentTiddler>get[toc-exclude]]
\function tf.toc-excludeYes() [<currentTiddler>format:titlelist[]] \function tf.toc-excludeYes() [<currentTiddler>format:titlelist[]]
\function tf.toc-exclude() [<tf.toc-getExclude>match[yes]then<tf.toc-excludeYes>] :else[<tf.toc-getExclude>]
\procedure toc-body(tag,sort:"",itemClassFilter,exclude,path) \procedure toc-body(tag,sort:"",itemClassFilter,exclude,path)
<ol class="tc-toc"> <ol class="tc-toc">
<!-- text substitution is needed for backwards compatibility --> <!-- text substitution is needed for backwards compatibility -->
<$list filter=`[all[shadows+tiddlers]tag<tag>!has[draft.of]$(sort)$] [subfilter<tf.toc-include>] -[<tag>] -[subfilter<exclude>]`> <$list filter=`[all[shadows+tiddlers]tag<tag>!has[draft.of]$(sort)$] [subfilter<tf.toc-include>] -[<tag>] -[subfilter<exclude>]`>
<$let _toc-exclude={{{ [<tf.toc-exclude>match[yes]then<tf.toc-excludeYes>] :else[<tf.toc-exclude>] }}} > <%if [<currentTiddler>] -[subfilter<tf.toc-exclude>] %>
<%if [<currentTiddler>] -[subfilter<_toc-exclude>] %>
<$let item=<<currentTiddler>> __path=<<tf.toc-newPath>> > <$let item=<<currentTiddler>> __path=<<tf.toc-newPath>> >
<$set name="__excluded" filter="[subfilter<exclude>] [<tag>] [subfilter<_toc-exclude>]"> <!-- adding tf.toc-exclude, excludes blocked elements from all visible sub-nodes -->
<li class=<<tf.toc-includedClass>>> <$set name="__excluded" filter="[subfilter<exclude>] [<tag>] [subfilter<tf.toc-exclude>]">
<li class=<<tf.toc-itemClass>>>
<% if [all[current]toc-link[no]] %> <% if [all[current]toc-link[no]] %>
<<toc-caption>> <<toc-caption>>
<% else %> <% else %>
@ -59,13 +61,9 @@ tags: $:/tags/Macro
</$set> </$set>
</$let> </$let>
<% endif %> <% endif %>
</$let>
</$list> </$list>
</ol> </ol>
\end \end
<!-- log -->
<!-- <$log tag=<<tag>> _t-e=<<_toc-exclude>> ct=<<currentTiddler>> sub={{{ [subfilter<_toc-exclude>]}}} exclude=<<exclude>>/> -->
<!-- log -->
<!-- ======================================= <!-- =======================================
Simple toc macro which shows the full tree Simple toc macro which shows the full tree
@ -100,7 +98,7 @@ This macro is _not_ used by other toc-macros
\procedure toc-linked-expandable-body(tag,sort:"",itemClassFilter,exclude,path) \procedure toc-linked-expandable-body(tag,sort:"",itemClassFilter,exclude,path)
<$qualify name="toc-state" title=<<tf.toc-stateTitle>> > <$qualify name="toc-state" title=<<tf.toc-stateTitle>> >
<li class=<<tf.toc-getItemClass>>> <li class=<<tf.toc-itemClass>>>
<!-- v5.1.23 use target-field if present in tiddler --> <!-- v5.1.23 use target-field if present in tiddler -->
<$link to={{{ [<currentTiddler>get[target]else<currentTiddler>] }}}> <$link to={{{ [<currentTiddler>get[target]else<currentTiddler>] }}}>
<<toc-item>> <<toc-item>>
@ -119,7 +117,7 @@ This macro is _not_ used by other toc-macros
\procedure toc-unlinked-expandable-body(tag,sort:"",itemClassFilter,exclude,path) \procedure toc-unlinked-expandable-body(tag,sort:"",itemClassFilter,exclude,path)
<$qualify name="toc-state" title=<<tf.toc-stateTitle>>> <$qualify name="toc-state" title=<<tf.toc-stateTitle>>>
<li class=<<tf.toc-getItemClass>>> <li class=<<tf.toc-itemClass>>>
<<toc-item isUnlinked:"yes">> <<toc-item isUnlinked:"yes">>
<!-- TODO auto expand --> <!-- TODO auto expand -->
<% if [<toc-state>get[text]match[open]] %> <% if [<toc-state>get[text]match[open]] %>
@ -139,10 +137,9 @@ Shows an expandable toc. Item always have an open/close chevron
<ol class="tc-toc toc-expandable"> <ol class="tc-toc toc-expandable">
<!-- text substitution is needed for backwards compatibility --> <!-- text substitution is needed for backwards compatibility -->
<$list filter=`[all[shadows+tiddlers]tag<tag>!has[draft.of]$(sort)$] [subfilter<tf.toc-include>] -[<tag>] -[subfilter<exclude>]`> <$list filter=`[all[shadows+tiddlers]tag<tag>!has[draft.of]$(sort)$] [subfilter<tf.toc-include>] -[<tag>] -[subfilter<exclude>]`>
<$let _toc-exclude={{{ [<tf.toc-exclude>match[yes]then<tf.toc-excludeYes>] :else[<tf.toc-exclude>] }}} > <%if [<currentTiddler>] -[subfilter<tf.toc-exclude>] %>
<%if [<currentTiddler>] -[subfilter<_toc-exclude>] %>
<$let __path=<<tf.toc-newPath>>> <$let __path=<<tf.toc-newPath>>>
<$set name="__excluded" filter="[subfilter<exclude>] [<tag>] [subfilter<_toc-exclude>]"> <$set name="__excluded" filter="[subfilter<exclude>] [<tag>] [subfilter<tf.toc-exclude>]">
<% if [all[current]toc-link[no]] %> <% if [all[current]toc-link[no]] %>
<$macrocall <$macrocall
$name="toc-unlinked-expandable-body" $name="toc-unlinked-expandable-body"
@ -157,14 +154,13 @@ Shows an expandable toc. Item always have an open/close chevron
</$set> </$set>
</$let> </$let>
<% endif %> <% endif %>
</$let>
</$list> </$list>
</ol> </ol>
\end \end
\procedure toc-linked-selective-expandable-body(tag,sort:"",itemClassFilter,exclude,path) \procedure toc-linked-selective-expandable-body(tag,sort:"",itemClassFilter,exclude,path)
<$qualify name="toc-state" title=<<tf.toc-stateTitle>>> <$qualify name="toc-state" title=<<tf.toc-stateTitle>>>
<li class=<<tf.toc-getItemClass>>> <li class=<<tf.toc-itemClass>>>
<!-- v5.1.23 use target-field if present in tiddler --> <!-- v5.1.23 use target-field if present in tiddler -->
<$link to={{{ [<currentTiddler>get[target]else<currentTiddler>] }}}> <$link to={{{ [<currentTiddler>get[target]else<currentTiddler>] }}}>
<% if [all[current]tagging[]] -[subfilter<exclude>] +[limit[1]] %> <% if [all[current]tagging[]] -[subfilter<exclude>] +[limit[1]] %>
@ -189,7 +185,7 @@ Shows an expandable toc. Item always have an open/close chevron
\procedure toc-unlinked-selective-expandable-body(tag,sort:"",itemClassFilter,exclude,path) \procedure toc-unlinked-selective-expandable-body(tag,sort:"",itemClassFilter,exclude,path)
<$qualify name="toc-state" title=<<tf.toc-stateTitle>> > <$qualify name="toc-state" title=<<tf.toc-stateTitle>> >
<li class=<<tf.toc-getItemClass>>> <li class=<<tf.toc-itemClass>>>
<% if [all[current]tagging[]] -[subfilter<exclude>] +[limit[1]] %> <% if [all[current]tagging[]] -[subfilter<exclude>] +[limit[1]] %>
<<toc-item isUnlinked:"yes">> <<toc-item isUnlinked:"yes">>
<% else %> <% else %>
@ -219,10 +215,9 @@ If an item has no children, there is no open/close chevron
<ol class="tc-toc toc-selective-expandable"> <ol class="tc-toc toc-selective-expandable">
<!-- text substitution is needed for backwards compatibility --> <!-- text substitution is needed for backwards compatibility -->
<$list filter=`[all[shadows+tiddlers]tag<tag>!has[draft.of]$(sort)$] [subfilter<tf.toc-include>] -[<tag>] -[subfilter<exclude>]`> <$list filter=`[all[shadows+tiddlers]tag<tag>!has[draft.of]$(sort)$] [subfilter<tf.toc-include>] -[<tag>] -[subfilter<exclude>]`>
<$let _toc-exclude={{{ [<tf.toc-exclude>match[yes]then<tf.toc-excludeYes>] :else[<tf.toc-exclude>] }}} > <%if [<currentTiddler>] -[subfilter<tf.toc-exclude>] %>
<%if [<currentTiddler>] -[subfilter<_toc-exclude>] %>
<$let __path=<<tf.toc-newPath>>> <$let __path=<<tf.toc-newPath>>>
<$set name="__excluded" filter="[subfilter<exclude>] [<tag>] [subfilter<_toc-exclude>]"> <$set name="__excluded" filter="[subfilter<exclude>] [<tag>] [subfilter<tf.toc-exclude>]">
<% if [all[current]toc-link[no]] %> <% if [all[current]toc-link[no]] %>
<$macrocall <$macrocall
$name="toc-unlinked-selective-expandable-body" $name="toc-unlinked-selective-expandable-body"
@ -237,7 +232,6 @@ If an item has no children, there is no open/close chevron
</$set> </$set>
</$let> </$let>
<% endif %> <% endif %>
</$let>
</$list> </$list>
</ol> </ol>
\end \end