Add a sort parameter to the TOC macro

As requested by @giffmex
print-window-tiddler
Jermolene 2014-08-20 22:48:07 +01:00
rodzic 81a426659e
commit 8041e3bef2
3 zmienionych plików z 30 dodań i 12 usunięć

Wyświetl plik

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

Wyświetl plik

@ -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>
"/>

Wyświetl plik

@ -16,6 +16,13 @@ There are several variants of the macro:
|!Position |!Name |!Description |!Default | |!Position |!Name |!Description |!Default |
|1st |tag |The root tag that identifies the top level of the hierarchy | | |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 ! Examples