toc-selective-expandable macro sort option

333 views
Skip to first unread message

Mohammad

unread,
Aug 6, 2018, 2:43:36 PM8/6/18
to TiddlyWiki
How is it possible to use toc-selective-expandable  and 
  • Sort the first level by caption
  • The second and third level by manual order in list filed

Mohammad

TonyM

unread,
Aug 6, 2018, 9:47:57 PM8/6/18
to TiddlyWiki
Mohammad,

Build your own toc macros with the first level sorted as desired, then second and subsequent levels with no sorting, and the recursive process mentioned by myself recently.

I have being looking for some example code I have but have not found it yet.

Regards
Tony

Mohammad

unread,
Aug 7, 2018, 4:00:05 AM8/7/18
to TiddlyWiki
Tony,
 Would you please explain a little more! I did not understand how it can be done!

Best
Mohammad

TonyM

unread,
Aug 7, 2018, 4:56:11 AM8/7/18
to TiddlyWiki
Mohammad,

Consider this psydo code

Here is some psudo code

\define first-level(roottag)
Call/list <<remaining-levels tiddler>> for every tiddler tagged with root-tag
 
Sort the first level by caption (Children)
\end


\define remaining-levels(tag)
Call/list <<remaining-levels tiddler>>
 
by manual order in list filed for every tiddler tagged with $tag$
 
(grandchildren and greatgrandchildren etc..)
\end


and call with 
<<first-level roottag>>

I am sure you have the skills to fill this out, but don't hesitate to ask.

If you want to stop the TOC going more than three levels deep just rename remaining-levels to children, and have it call a new macro called grand children which does not call any other macro.
 
Regards


Tony

TonyM

unread,
Aug 7, 2018, 4:58:54 AM8/7/18
to TiddlyWiki
Overly technical background

Mohammad,

On tiddlywiki.com we can see a number of toc macros mentioned
toc, toc-expandable, toc-selective-expandable, toc-tabbed-internal-nav and toc-tabbed-external-nav

Advanced Search for one that interests you such as toc-selective-expandable and you will find it in the shadow $:/core/macros/toc

Open $:/core/macros/toc in edit mode and you can see how it works


```
\define toc-selective-expandable(tag,sort:"",itemClassFilter,exclude,path)
<$vars tag="""$tag$""" sort="""$sort$""" itemClassFilter="""$itemClassFilter$""" excluded="""$exclude$ -[[$tag$]]""" path="""$path$/$tag$""">
  <ol class="tc-toc toc-selective-expandable">
    <$list filter="""[all[shadows+tiddlers]tag[$tag$]!has[draft.of]$sort$] -[[$tag$]] $exclude$""">
      <$list filter="[all[current]toc-link[no]]" variable="ignore" emptyMessage=<<toc-selective-expandable-empty-message>> >
        <$macrocall $name=toc-unlinked-selective-expandable-body tag="""$tag$""" sort="""$sort$""" itemClassFilter="""$itemClassFilter$""" exclude=<<excluded>> path=<<path>> >
      </$list>
    </$list>
  </ol>
</$vars>
\end
```


;Which you work through carefully and you find it "calls"  `<<toc-selective-expandable-empty-message>>` If there is nothing to process which then calls toc-linked-selective-expandable-body
;Or the above calls toc-unlinked-selective-expandable-body if there is some thing


```
\define toc-linked-selective-expandable-body(tag,sort:"",itemClassFilter:" ",exclude,path)
<$set name="toc-state" value=<<qualify """$:/state/toc$path$-$(currentTiddler)$""">>>
  <$set name="toc-item-class" filter="""$itemClassFilter$""" emptyValue="toc-item" value="toc-item-selected" >
    <li class=<<toc-item-class>>>
      <$link>
          <$list filter="[all[current]tagging[]limit[1]]" variable="ignore" emptyMessage="<$button class='tc-btn-invisible'>{{$:/core/images/blank}}</$button>">
          <$reveal type="nomatch" state=<<toc-state>> text="open">
            <$button set=<<toc-state>> setTo="open" class="tc-btn-invisible tc-popup-keep">
              {{$:/core/images/right-arrow}}
            </$button>
          </$reveal>
          <$reveal type="match" state=<<toc-state>> text="open">
            <$button set=<<toc-state>> setTo="close" class="tc-btn-invisible tc-popup-keep">
              {{$:/core/images/down-arrow}}
            </$button>
          </$reveal>
        </$list>
        <<toc-caption>>
      </$link>
      <$reveal type="match" state=<<toc-state>> text="open">
        <$macrocall $name="toc-selective-expandable" tag=<<currentTiddler>> sort="""$sort$""" itemClassFilter="""$itemClassFilter$""" exclude="""$exclude$""" path="""$path$"""/>
      </$reveal>
    </li>
  </$set>
</$set>
\end
```




;Now notice how this in turn calls toc-selective-expandable!


;toc-unlinked-selective-expandable-body

```
\define toc-unlinked-selective-expandable-body(tag,sort:"",itemClassFilter:" ",exclude,path)
<$set name="toc-state" value=<<qualify """$:/state/toc$path$-$(currentTiddler)$""">>>
  <$set name="toc-item-class" filter="""$itemClassFilter$""" emptyValue="toc-item" value="toc-item-selected">
    <li class=<<toc-item-class>>>
      <$list filter="[all[current]tagging[]limit[1]]" variable="ignore" emptyMessage="<$button class='tc-btn-invisible'>{{$:/core/images/blank}}</$button> <$view field='caption'><$view field='title'/></$view>">
        <$reveal type="nomatch" state=<<toc-state>> text="open">
          <$button set=<<toc-state>> setTo="open" class="tc-btn-invisible tc-popup-keep">
            {{$:/core/images/right-arrow}}
            <<toc-caption>>
          </$button>
        </$reveal>
        <$reveal type="match" state=<<toc-state>> text="open">
          <$button set=<<toc-state>> setTo="close" class="tc-btn-invisible tc-popup-keep">
            {{$:/core/images/down-arrow}}
            <<toc-caption>>
          </$button>
        </$reveal>
      </$list>
      <$reveal type="match" state=<<toc-state>> text="open">
        <$macrocall $name="""toc-selective-expandable""" tag=<<currentTiddler>> sort="""$sort$""" itemClassFilter="""$itemClassFilter$""" exclude="""$exclude$""" path="""$path$"""/>
      </$reveal>
    </li>
  </$set>
</$set>
\end
```




Now notice how this in turn calls toc-selective-expandable!

So lets make this simpler

toc-selective-expandable > toc-linked-selective-expandable-body (Via empty) > Calls the first macro "toc-selective-expandable"
                         
Or
                         
> toc-unlinked-selective-expandable-body > Calls the first macro "toc-selective-expandable"


So the first macro is repeatedly called until very part of the Tree is visited.

Regards
Tony

Mohammad

unread,
Aug 7, 2018, 5:16:51 AM8/7/18
to TiddlyWiki
Thanks Tony!
So it seems I should go inside those macros to understand what going ob there!
By the way the standard macro toc-selective-expandable seems to get a sort parameter which apply to all root and childern!


<div class="tc-table-of-contents">
<<toc-selective-expandable "slideshow" "sort[caption]">>
</div>

So, it seems I cannot use the default macro

/Mohammad

PMario

unread,
Aug 7, 2018, 6:06:10 AM8/7/18
to TiddlyWiki
That's right. .. The default TOC macros cover about 80% of usecases. The other 20% are highly user specific and much harder to implement in a generic way. ... That's why they may be plugins .. .

 - I did 1 plugin, which is called: tocP ... "parent based" TOC. see: https://wikilabs.github.io/editions/tocP/ ... which probably won't work for your usecase

 - I also did an experimental version named: "toc merge" which atm overwrites the "core toc macros". That's why it is still an experiment. You can learn more here in the group. This thread also contains an attachment, that you can use for testing.

This one may be a starting point for your usecase. ... It actually could do what you want. ... but ... it still needs a lot of manual adjustments, which may be too hard for "end users" ... It should be OK for advanced users. .....

There is no docs, so have a closer look at the linked threads. ... all of them!

have fun!
mario





Mohammad

unread,
Aug 7, 2018, 8:56:36 AM8/7/18
to TiddlyWiki
Thanks Mario!
Good stuff!

Mohammad

DemoniWaari

unread,
Aug 8, 2018, 3:33:47 AM8/8/18
to TiddlyWiki
Hi Mohammad,

I had a similar problem as you but in my case my first level is manual and third level is by creation date and this method works fine. I have not tried this for your case though. What you need to do it sort your TOC according to a field, e.g., <<toc-selective-expandable 'Contents' sort{!!sorting}>> and make a field called sorting in the Contents tiddler and write caption there. This will sort the first level by caption. Then on the second and third level tiddlers you will make both sorting and list fields. In the sorting field you will type list (now it references to the list field) and in the list field you will write the order in manually.

Though I did notice that if I put this TOC in the side bar, my first level manual sorting does not look the same as in the tiddler itself and there it is sorted by title.

Mohammad

unread,
Aug 8, 2018, 7:17:57 AM8/8/18
to TiddlyWiki
Good trick!
Unfortunately did not work for me! What I did now is I removed the caption from second and third level and only used in the first level now toc-selective-expandable works for me! but if you use in second level in any child a caption, then again it confuses and the sorted result is wrong!


Mohammad
Reply all
Reply to author
Forward
0 new messages