Add a sort parameter to the TOC macro

As requested by @giffmex
This commit is contained in:
Jermolene 2014-08-20 22:48:07 +01:00
parent 81a426659e
commit 8041e3bef2
3 changed files with 30 additions and 12 deletions

View File

@ -1,9 +1,9 @@
title: $:/core/macros/toc
tags: $:/tags/Macro
\define toc(tag)
\define toc(tag,sort:"")
<ol>
<$list filter="[tag[$tag$]]">
<$list filter="[tag[$tag$]$sort$]">
<li>
<$link>
<$view field="title"/>
@ -14,7 +14,7 @@ tags: $:/tags/Macro
</ol>
\end
\define toc-expandable-body(tag,show-button-filter)
\define toc-expandable-body(tag,sort:"")
<$set name="toc-state" value=<<qualify "$:/state/toc/$tag$-$(currentTiddler)$">>>
<li>
<$link>
@ -31,21 +31,21 @@ tags: $:/tags/Macro
<$view field="title"/>
</$link>
<$reveal type="match" state=<<toc-state>> text="open">
<$macrocall $name="toc-expandable" tag=<<currentTiddler>>/>
<$macrocall $name="toc-expandable" tag=<<currentTiddler>> sort="$sort$"/>
</$reveal>
</li>
</$set>
\end
\define toc-expandable(tag)
\define toc-expandable(tag,sort:"")
<ol>
<$list filter="[tag[$tag$]]">
<<toc-expandable-body tag:"$tag$">>
<$list filter="[tag[$tag$]$sort$]">
<<toc-expandable-body tag:"$tag$" sort:"$sort$">>
</$list>
</ol>
\end
\define toc-selective-expandable-body(tag,show-button-filter)
\define toc-selective-expandable-body(tag,sort:"")
<$set name="toc-state" value=<<qualify "$:/state/toc/$tag$-$(currentTiddler)$">>>
<li>
<$link>
@ -64,16 +64,16 @@ tags: $:/tags/Macro
<$view field="title"/>
</$link>
<$reveal type="match" state=<<toc-state>> text="open">
<$macrocall $name="toc-selective-expandable" tag=<<currentTiddler>>/>
<$macrocall $name="toc-selective-expandable" tag=<<currentTiddler>> sort="$sort$"/>
</$reveal>
</li>
</$set>
\end
\define toc-selective-expandable(tag)
\define toc-selective-expandable(tag,sort:"")
<ol>
<$list filter="[tag[$tag$]]">
<<toc-selective-expandable-body tag:"$tag$">>
<$list filter="[tag[$tag$]$sort$]">
<<toc-selective-expandable-body tag:"$tag$" sort:"$sort$">>
</$list>
</ol>
\end

View File

@ -0,0 +1,11 @@
title: TableOfContentsMacro Sorted Expandable Example
caption: Sorted Expandable
tags: table-of-contents-example
!! Sorted Expandable Table of Contents
<$macrocall $name="wikitext-example-without-html"
src="<div class='tw-table-of-contents'>
<<toc-expandable 'Contents' 'sort[title]'>>
</div>
"/>

View File

@ -16,6 +16,13 @@ There are several variants of the macro:
|!Position |!Name |!Description |!Default |
|1st |tag |The root tag that identifies the top level of the hierarchy | |
|2nd |sort |Optional sorting subfilter (eg `sort[title]`) | |
The ''tag'' and ''sort'' parameters are combined to make a filter expression of the form:
```
[tag[$tag$]$sort$]
```
! Examples