Skip to content

Commit

Permalink
Extend toc macro so that links can be disabled
Browse files Browse the repository at this point in the history
This allows table of contents to contain heading entries that do not
function as links, like the one in the sidebar.
  • Loading branch information
Jermolene committed Sep 5, 2014
1 parent 7e93c93 commit ba3f800
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 8 deletions.
70 changes: 64 additions & 6 deletions core/wiki/macros/toc.tid
Expand Up @@ -5,18 +5,18 @@ tags: $:/tags/Macro
<ol class="tc-toc">
<$list filter="[tag[$tag$]$sort$]">
<li>
<$link>
<$list filter="[is[current]toc-link[no]]" emptyMessage="<$link><$view field='caption'><$view field='title'/></$view></$link>">

This comment has been minimized.

Copy link
@tobibeer

tobibeer Dec 2, 2014

Contributor

What does this feature have to do with filters?

This comment has been minimized.

Copy link
@Jermolene

Jermolene Dec 2, 2014

Owner

Sorry @tobibeer I'm not sure what you mean - which feature are you referring to?

This comment has been minimized.

Copy link
@tobibeer

tobibeer Dec 2, 2014

Contributor

the feature where a toc-entry would not be rendered as a link
I get it now, the filter is used to do the conditional rendering

<$view field="caption">
<$view field="title"/>
</$view>
</$link>
</$list>
<$macrocall $name="toc" tag=<<currentTiddler>>/>
</li>
</$list>
</ol>
\end

\define toc-expandable-body(tag,sort:"")
\define toc-linked-expandable-body(tag,sort:"")
<$set name="toc-state" value=<<qualify "$:/state/toc/$tag$-$(currentTiddler)$">>>
<li>
<$link>
Expand All @@ -41,15 +41,43 @@ tags: $:/tags/Macro
</$set>
\end

\define toc-unlinked-expandable-body(tag,sort:"")
<$set name="toc-state" value=<<qualify "$:/state/toc/$tag$-$(currentTiddler)$">>>
<li>
<$reveal type="nomatch" state=<<toc-state>> text="open">
<$button set=<<toc-state>> setTo="open" class="tc-btn-invisible">
{{$:/core/images/right-arrow}}
<$view field="caption">
<$view field="title"/>
</$view>
</$button>
</$reveal>
<$reveal type="match" state=<<toc-state>> text="open">
<$button set=<<toc-state>> setTo="close" class="tc-btn-invisible">
{{$:/core/images/down-arrow}}
<$view field="caption">
<$view field="title"/>
</$view>
</$button>
</$reveal>
<$reveal type="match" state=<<toc-state>> text="open">
<$macrocall $name="toc-expandable" tag=<<currentTiddler>> sort="$sort$"/>
</$reveal>
</li>
</$set>
\end

\define toc-expandable(tag,sort:"")
<ol class="tc-toc toc-expandable">
<$list filter="[tag[$tag$]$sort$]">
<<toc-expandable-body tag:"$tag$" sort:"$sort$">>
<$list filter="[is[current]toc-link[no]]" emptyMessage="<<toc-linked-expandable-body tag:'$tag$' sort:'$sort$'>>">
<<toc-unlinked-expandable-body tag:"$tag$" sort:"$sort$">>
</$list>
</$list>
</ol>
\end

\define toc-selective-expandable-body(tag,sort:"")
\define toc-linked-selective-expandable-body(tag,sort:"")
<$set name="toc-state" value=<<qualify "$:/state/toc/$tag$-$(currentTiddler)$">>>
<li>
<$link>
Expand All @@ -76,10 +104,40 @@ tags: $:/tags/Macro
</$set>
\end

\define toc-unlinked-selective-expandable-body(tag,sort:"")
<$set name="toc-state" value=<<qualify "$:/state/toc/$tag$-$(currentTiddler)$">>>
<li>
<$list filter="[all[current]tagging[]limit[1]]" 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">
{{$:/core/images/right-arrow}}
<$view field="caption">
<$view field="title"/>
</$view>
</$button>
</$reveal>
<$reveal type="match" state=<<toc-state>> text="open">
<$button set=<<toc-state>> setTo="close" class="tc-btn-invisible">
{{$:/core/images/down-arrow}}
<$view field="caption">
<$view field="title"/>
</$view>
</$button>
</$reveal>
</$list>
<$reveal type="match" state=<<toc-state>> text="open">
<$macrocall $name="toc-selective-expandable" tag=<<currentTiddler>> sort="$sort$"/>
</$reveal>
</li>
</$set>
\end

\define toc-selective-expandable(tag,sort:"")
<ol class="tc-toc toc-selective-expandable">
<$list filter="[tag[$tag$]$sort$]">
<<toc-selective-expandable-body tag:"$tag$" sort:"$sort$">>
<$list filter="[is[current]toc-link[no]]" emptyMessage="<<toc-linked-selective-expandable-body tag:'$tag$' sort:'$sort$'>>">
<<toc-unlinked-selective-expandable-body tag:"$tag$" sort:"$sort$">>
</$list>
</$list>
</ol>
\end
8 changes: 6 additions & 2 deletions editions/tw5.com/tiddlers/macros/TableOfContentsMacro.tid
@@ -1,10 +1,14 @@
title: TableOfContentsMacro
tags: macros
modified: 20140828080307785
modified: 20140905084423561

The table of contents macro produces a hierarchical tree of tiddlers based on their tags.

The top level entries of the table of contents are defined by a root tag. The subentries under each of those entries are tagged with the title of the entry. Entries can be ordered using the `list` field as described in TiddlerTags. The text for each entry is taken from the ''caption'' field if it is present, otherwise the ''title'' is used.
The top level entries of the table of contents are defined by a root tag. The subentries under each of those entries are tagged with the title of the entry. Entries can be ordered using the `list` field of the tag tiddler as described in TiddlerTags.

The text for each entry is taken from the ''caption'' field if it is present, otherwise the ''title'' is used.

Entries are rendered as a link to the corresponding tiddler unless the tiddler has the value ''no'' in the field ''toc-link''. In the examples below, the entry SecondThree is set up in this way to not appear as a link.

There are several variants of the macro:

Expand Down
@@ -1,5 +1,6 @@
title: SecondThree
tags: Second
list: SecondThreeOne SecondThreeTwo SecondThreeThree
toc-link: no

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

5 comments on commit ba3f800

@giffmex
Copy link
Contributor

@giffmex giffmex commented on ba3f800 Sep 5, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't wait to see this! An awesome feature I would never have imagined possible.

@Jermolene
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @giffmex - was pretty easy to do (albeit verbose). I've just pushed a build to http://tw5test.tiddlyspot.com for you to look at

@giffmex
Copy link
Contributor

@giffmex giffmex commented on ba3f800 Sep 5, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmmm...not sure it is functioning as we first intended. I created a tiddler and added

<div class='tc-table-of-contents'>
<<toc-selective-expandable 'Topics'>>
</div>

Then created New Tiddler 1 and New Tiddler 2. Both were tagged Topics, but the second one has a field of toc-link with the word no in it. The second one doesn't appear at all in the list. But what we want is for the title to appear, without being a link to the tiddler. Also, will it be possible, for my own uses later, to assign a different color to these, to distinguish them from actual links? Even for our purposes, I am afraid a user might click on one of these 'dead' links and think something is wrong. How might we distinguish them from the actual links?

@Jermolene
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then created New Tiddler 1 and New Tiddler 2. Both were tagged Topics, but the second one has a field of toc-link with the word no in it. The second one doesn't appear at all in the list. But what we want is for the title to appear, without being a link to the tiddler.

Then something has gone wrong - look at the example in TableOfContentsMacro, where it is working.

Also, will it be possible, for my own uses later, to assign a different color to these, to distinguish them from actual links? Even for our purposes, I am afraid a user might click on one of these 'dead' links and think something is wrong. How might we distinguish them from the actual links?

You can use CSS to set different colours; the non-linked entries have different HTML. The examples in TableOfContentsMacro show this.

@giffmex
Copy link
Contributor

@giffmex giffmex commented on ba3f800 Sep 5, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, I must have done something wrong. The example tiddlers are proof enough to me. Will play with it more carefully later.

Please sign in to comment.