Recursive Wikitext for TOC Customisation and More (Shared Knowledge)

572 views
Skip to first unread message

TonyM

unread,
Jan 17, 2020, 9:09:22 PM1/17/20
to TiddlyWiki
Folks,

We see a range of requests to customise the Table Of Contents macros such as here to colour items. Often we try and address each of these bespoke requests using the existing TOC macros. This perhaps because the nature of a TOC is a little less intuitive than most. It requires a Recursive process. I thought I would share some details on this recursive code pattern and invite others to produce additional features, ideally based on those prior so people can learn from them.

The Following examples work if placed in a single tiddler on TiddlyWiki.com
\define each-other-level(filter)
<li><$link to=<<currentTiddler>> ><$text text=<<currentTiddler>>/></$link></li>
<ul>
<$list filter="$filter$">
   
<<each-other-level $filter$>>
</$list>
</
ul>
\end
\define first-level(filter)
<ul>
<$list filter="$filter$">
   
<<each-other-level $filter$>>
</$list>
</
ul>
\end

Start in TableOfContents<br>
<$tiddler tiddler="TableOfContents">

<<first-level "[is[current]tagging[]]">>

</$tiddler>



See how the at the bottom we start calling the first-level macro, then this calls each-other-level for each item in the list.

The recursion then occurs when inside each-other-level we call each-other-level

Not how the list is wrapped in `<ul>` and each line with `<li>` this makes use of HTML to generate lists and will nest them.

Soon I will post a more advanced version with Notes.

Regards
Tony

TonyM

unread,
Jan 17, 2020, 9:36:07 PM1/17/20
to TiddlyWiki
Rather than Provide a link to each tiddler in our toc we can use a tag pill on the current tiddler.

You can use a tag pill to drag and drop the order of items so tagged;

Here I only changed the second line in the previous example.

\define each-other-level(filter)
<li><$macrocall $name=tag tag=<<currentTiddler>>/></li>

<ul>
<$list filter="$filter$">
   
<<each-other-level $filter$>>
</$list>
</
ul>
\end
\define first-level(filter)
<ul>
<$list filter="$filter$">
   
<<each-other-level $filter$>>
</$list>
</
ul>
\end


Start in TableOfContents<br>
<$tiddler tiddler="TableOfContents">


<<first-level "[is[current]tagging[]]">>


</$tiddler>

Mat

unread,
Jan 18, 2020, 4:52:09 AM1/18/20
to TiddlyWiki
Just a note:

<$link to=<<currentTiddler>> ><$text text=<<currentTiddler>>/></$link>

has (thankfully) been simplified to this syntax:

<$link/>

<:-)

Mat

unread,
Jan 18, 2020, 5:00:41 AM1/18/20
to TiddlyWiki
Actually, that goes for the tag macro too. It uses current tiddler as default.

<:-)

TonyM

unread,
Jan 18, 2020, 6:24:32 AM1/18/20
to TiddlyWiki
Folks,

Lets go advanced based on my first post.

The Attached JSON can be dropped on TiddlyWiki.com or any wiki, it is still built on the first minimal example.

This example is now to iterate the whole TOC but then you can activate details and button on the toc. 

It also demonstrates how easy it is to use tiddlywikis default buttons when your list is driven using the CurrentTiddler variable.

There are range of trick and code patterns built into this, perhaps a useful project for someone getting to know TiddlyWiki. I have pasted the tiddler content below for with notes and challenges for your reference.

Here a screen shot to tempt you;

Snag_d3b0063.png


The code in the attached tiddler
\define each-other-level(filter)
<$set name=level filter="[<level>add[1]]">
<$wikify name=branch-number text=<<append-branch-number>> >
<ul>
<li><<branch-number>><!--$transclude tiddler={{!!icon}}/--> <$link to=<<currentTiddler>> ><$text text=<<currentTiddler>>/></$link>
<$list filter="[{Recursion-Demo!!show-details}match[yes]]" variable=nul> (level:<<level>>) <!--parent: <<parentTiddler>--> <!--<position-in-parentTiddler-list>--></$list>
<$list filter="[{Recursion-Demo!!show-buttons}match[yes]]" variable=nul> {{$:/core/ui/Buttons/permalink}} {{||$:/core/ui/Buttons/edit}} {{||$:/core/ui/Buttons/clone}}  <<copy-title>> <<copy-content>></$list>
</li>
<$set name=parentTiddler value=<<currentTiddler>> >
<$list filter="$filter$">
   <<each-other-level $filter$>>
</$list>
</$set>
</ul>
</$wikify></$set>
\end
\define first-level(filter)
<h3><$link to=<<currentTiddler>> ><$text text=<<currentTiddler>>/></$link></h3>
<$set name=parentTiddler value=<<currentTiddler>> >
<$set name=level value="">
<$list filter="$filter$">
   <<each-other-level $filter$>>
</$list>
</$set></$set>
End all<br>
\end
\define append-branch-number() $(branch-number)$<<position-in-parentTiddler-list>>.
\define position-in-list() {{{  +[allbefore:include<currentTiddler>count[]] }}}
\define position-in-parentTiddler-list() 
<$list filter="[<parentTiddler>tagging[]] +[allbefore:include<currentTiddler>count[]]" variable=position><$text text=<<position>>/></$list>
\end
\define copy-title()
<$button message="tm-copy-to-clipboard" param=<<currentTiddler>> tooltip="Copy the Tiddler Title to the clipboard" class="tc-btn-invisible">
{{$:/core/images/copy-clipboard}}title
</$button>
\end
\define copy-content()
<$button message="tm-copy-to-clipboard" param={{!!text}} tooltip="Copy the Tiddler Content to the clipboard" class="tc-btn-invisible">
{{$:/core/images/copy-clipboard}}content
</$button>
\end

<h2>Recursion and a Table of Contents</h2>

:This is a demonstration of simple <$button tooltip="No other tiddler is required to make this work, only the tiddlers to be listed, does not use the TOC macros" class="tc-btn-invisible tc-tiddlylink">"single tiddler"</$button> recursion macro, allowing designer influence of a TOC. 
*A Table of contents Macro is designed to build a hierarchy from tiddlers tagging tiddlers
*All that is needed is to call one macro from another. However it will call the second macro for each level down it finds.
**The two essential macros are ''first-level'' and ''each-other-level''.
**And additional macro "append-branch" is define to concatenate the current level on a branch.
*When all items are listed at a given level it falls back to the last items in the previous level
*This macro is not checking to Avoid an infinite loop that may cause infinite recursion
*The "level" variable displayed in (n) shows how many levels deep you are
*Icons will be displayed if they exist in tiddlers (uncomment `<!--$transclude tiddler={{!!icon}}/-->`)
*by setting the parentTiddler before calling the next level we can search its list field to see where the current tiddler comes in the list (this adds a bit of time using the trick discussed [[here|https://groups.google.com/forum/?hl=en#!topic/tiddlywiki/wY6haW2cYMA]]
*Change `<!--parent: <<parentTiddler>-->` to `<parent: <<parentTiddler>>` to see each parent displayed.
;Challenges
*Generate a way to generate a number for the exact position in the list eg 1, 2, 3... in sequence for every tiddler listed
*A Popup or modal to preview the content of each listed tiddler, perhaps even with mouse over.
<$checkbox field="show-details" checked="yes" unchecked="no" default="no"> Show details</$checkbox>
<$checkbox field="show-buttons" checked="yes" unchecked="no" default="no"> Show Action Buttons</$checkbox>

<$tiddler tiddler="TableOfContents">
<$set name=branch-number value="">
 <<first-level "[is[current]tagging[]]">>
</$set>
</$tiddler>

I am creating a modified version of the tag macro, where it displays a label rather than long and unwieldy tiddler titles, to be made available on any tiddler than has children, ie tags, so that drag and drop reordering is simple.

Enjoy this and please ask questions or provide feedback, just as mark just did.

Thanks
Tony
Recursion-demo.json

Mohammad

unread,
Jan 18, 2020, 8:21:04 AM1/18/20
to TiddlyWiki
Great addition Tony!

I may recommend to change line 6 in the script from <ul> to

<ul style="list-style:none;">



--Mohammad

Mohammad

unread,
Jan 18, 2020, 8:41:16 AM1/18/20
to TiddlyWiki
Tony
I may also two small customization in UI
 - depth to be changed
 - small searchbox

A checkbox or setting can hide or show them.

--Mohammad

On Saturday, January 18, 2020 at 2:54:32 PM UTC+3:30, TonyM wrote:

Mohammad

unread,
Jan 18, 2020, 9:18:17 AM1/18/20
to TiddlyWiki
Added  to TW-Scripts



On Saturday, January 18, 2020 at 6:06:07 AM UTC+3:30, TonyM wrote:
Rather than Provide a link to each tiddler in our toc we can use a tag pill on the current tiddler.

You can use a tag pill to drag and drop the order of items so tagged;

This is what we use in Microsoft Word as outline view and one can drag and drop sections and rearrange them 

Mohammad

unread,
Jan 18, 2020, 9:48:37 AM1/18/20
to TiddlyWiki
A Clone of TOC-EXPANDABLE
but very simple and easy to customize


Hi again Tony!
 I just added a slider macro from TW-Scripts to your simple to understand toc macro to improve it

- the current code shows all entries and it takes time and make TW slow
- the new code
-- uses a slider macro so every first entry is in collapsed mode
-- as it does not render all the entries at once, TW seems faster as little rendering required
-- the code still is very easy to customize like colorifying, ...

Cheers
Mohammad

The improved code: equivalent to toc-expandable
--------------------------------------------------------

\define slider-toc(title, content)
<$set name="revealState" value=<<qualify "$:/state-reveal-$title$">>>
 <$reveal type="nomatch" state=<<revealState>> text="yes">
  <$button class="tc-btn-invisible tc-tiddlylink" set=<<revealState>> setTo="yes">
   {{$:/core/images/right-arrow}}
  </$button>
 </$reveal>
 <$reveal type="match" state=<<revealState>> text="yes">
  <$button class="tc-btn-invisible tc-tiddlylink" set=<<revealState>> setTo="no">
   {{$:/core/images/down-arrow}}
  </$button>
 </$reveal>
 <$link to=<<__title__>>><$view tiddler="""$title$""" field="caption">
  <$view tiddler="""$title$""" field="title"></$view>
 </$view></$link><br>
<$reveal type="match" state=<<revealState>> text="yes">
$content$
</$reveal>
</$set>
\end

\define each-other-level(filter)
<$macrocall $name=slider-toc title=<<currentTiddler>> 
content="""<ul>
<$list filter="$filter$">
   <<each-other-level $filter$>>
</$list>
</ul>"""/>
Tony-TOC-Expandable.tid

TonyM

unread,
Jan 21, 2020, 4:47:32 PM1/21/20
to TiddlyWiki
Mohammad,

Thanks for sharing. I note however there is no indicator if their is, or is not, any subtiddlers. If you are happy to provide a fix and a minimal example, as you have so far, then have a go of adding your slider to the bigger example it would be interesting. 

What are the changes to this example to add sliders ?

eg at at the top of \define each-other-level(filter)
<$macrocall $name=slider-toc title=<<currentTiddler>>
content="""
<ul>

then add
the macro slider-toc to the tiddler

Regards
Tony

Mohammad

unread,
Jan 21, 2020, 11:06:30 PM1/21/20
to TiddlyWiki
Hi Tony
Try this one

\define slider-toc(title, content)
<$set name="revealState" value=<<qualify "$:/state-reveal-$title$">>>
 <$reveal type="nomatch" state=<<revealState>> text="yes">
  <$button class="tc-btn-invisible tc-tiddlylink" set=<<revealState>> setTo="yes">
   {{$:/core/images/right-arrow}}
  </$button>
 </$reveal>
 <$reveal type="match" state=<<revealState>> text="yes">
  <$button class="tc-btn-invisible tc-tiddlylink" set=<<revealState>> setTo="no">
   {{$:/core/images/down-arrow}}
  </$button>
 </$reveal>
 <$link to=<<__title__>>><$view tiddler="""$title$""" field="caption">
  <$view tiddler="""$title$""" field="title"></$view>
 </$view></$link><br>
<$reveal type="match" state=<<revealState>> text="yes">
$content$
</$reveal>
</$set>
\end

\define each-other-level(filter)
<$macrocall $name=slider-toc title=<<currentTiddler>>  
content="""<ul>
<$list filter="$filter$">
<$list filter="[<currentTiddler>tagging[]count[]match[0]]" variable=ignore 
  emptyMessage=<<each-other-level $filter$>> >
  <$link to=<<currentTiddler>>><$view field="caption">
  <$view field="title"></$view>
 </$view></$link><br>
</$list>
</$list>
</ul>
"""/>
\end

\define level-content(filter)
<ul>
<$list filter="$filter$">
<$list filter="[<currentTiddler>tagging[]count[]match[0]]" variable=ignore 
  emptyMessage=<<each-other-level $filter$>> >
  <$link to=<<currentTiddler>>><$view field="caption">
  <$view field="title"></$view>
 </$view></$link><br>
</$list>
</$list>
</ul>
\end

\define first-level(filter)
<ul>
<$list filter="$filter$">
   <<each-other-level $filter$>>
</$list>
</ul>
\end


Start in TableOfContents<br>
<$tiddler tiddler="TableOfContents">

<<first-level "[is[current]tagging[]]">>

</$tiddler>

Mohammad

unread,
Jan 22, 2020, 12:21:34 AM1/22/20
to TiddlyWiki
Hi Tony,
 
This is an improved TOC-Expandable sports two button to collapse and expand all tiddlers in the table-of-contents
Also it is smart enough to hide the right arow for entries have no child.

I have created an experimental wiki on tiddlyspot will share later.

Drag and drop in tiddlywiki.com and see how amazingly it works!

toc-expandable-fig01.png



toc-expandable-fig02.png


Tony-TOC-Expandable 5.tid

Mohammad

unread,
Jan 22, 2020, 12:51:34 AM1/22/20
to TiddlyWiki
Tony!
 One feature is missing is when you open an entry from toc list from sidebar it is good to have it highlighted!
 I know Eric Shulman has developed some powerful toc macro in his http://tiddlytools.com/InsideTW/
 And those macro supports this! It seems when a tiddler in the toc is under focus its title in the toc list highlighted.

 I would like to ask Eric, if this can be simply added to your current toc macros!

--Mohammad
 

TonyM

unread,
Jan 22, 2020, 3:46:44 AM1/22/20
to TiddlyWiki
Mohammad

I would encourage any posts in this thread with TOC examples to build a good resource, be it searching the forum, what you add to twscripts and other examples.

My key point though was pointing out how when someone has a special need they can take the basic initial script and build on that rather than trying to force it into the default toc macros.

The only caviet is I have not tested for infinate loops however we could use the depth set at a high number to combat it.

However if someone is writing a book they are unlikely place a cheaper within a chapter so for many use cases a loop is unlikely to be created.

In fact illustrating how to stop infinite loops is another useful code pattern.

Your slider examples also add a lot to the code patterns.

Regards
Tont

Mat

unread,
Jan 22, 2020, 4:32:03 AM1/22/20
to TiddlyWiki
Mohammad wrote:
Drag and drop in tiddlywiki.com and see how amazingly it works!


Thanks, both of you, for sharing. Please note that recursions can cause problems also: For example, go to tiddlywiki.com and tag the HelloThere tiddler with "Examples" (i.e to create a loop because Examples is a subtiddler to HelloThere). This does not cause problems. But if you add Mohammads creation you get RSOE. I'm not sure how native TW avoids this but know it was something that was actively dealt with a few years back.

A wish: One major lacking feature of current ToC's is drag'n drop-ability. I.e to rearrange the branches in the tree. This would be the basis for a super useful outliner: The next step would be a feature to "open all tiddlers" in a tree or a subbranch. It'd be a very powerful tool for authoring longer texts.

<:-)

TonyM

unread,
Jan 22, 2020, 5:46:32 AM1/22/20
to TiddlyWiki
Mat

I am planing to provide an example of reordering the toc, but I ran down a number of rabbit holes which opened whole new worlds like in Alice in wonderland.

I have being very productive lately and hope to release many of my inventions. In truth I am not so good at releasing them because I am always polishing them up with new features.

I wish I had some of whatever Mohammad has.

I find sharing fundamental constructs that took time for me to understand well, then starting a conversation about them fun, interesting and inspiring. Some day I hope to take some De facto standards I built for myself and see them become dejure. Some would say I am a slow learner but I am not, I am a deep learner and that takes time and in time I will give more to the community.

But sometimes its the little tips, the every day tricks we all have, that have the most impact, once Shared.

regards
Tony

Mat

unread,
Jan 22, 2020, 6:41:52 AM1/22/20
to TiddlyWiki
TonyM wrote:

I am planing to provide an example of reordering the toc, [...] hope to release many of my inventions.


Exciting! I've wanted this for a long time (we had it in TWC!)  @Siniy-Kit made something for the native ToC in TW5 but I fail to use it.
 

In truth I am not so good at releasing them because I am always polishing them up with new features.


If the basics are in place, I think people would rather see something imperfect than nothing at all. Plus, adding features can be counter productive - it risks obscuring the basic features so the product seems irrelevant. Probably better to throw out a thing, then make a variant and put it out too, separately.

<:-)

TonyM

unread,
Jan 22, 2020, 6:54:19 AM1/22/20
to TiddlyWiki
Mat

I agree loading too many features into a solution is not good especialy when sharing so people can learn from it.

In part the features I am referring to are those that make the solution simple but customisable and based on higher quality design, such that its reusable and more likely to work with other solutions and plugins. I suppose this can mean a degree of perfectionisium that not every one will make use of, but hopefully it avoids side effects and compatibility issues.

Regards
Tony

Regards
Tony

Eric Shulman

unread,
Jan 22, 2020, 7:38:28 AM1/22/20
to TiddlyWiki
On Wednesday, January 22, 2020 at 1:32:03 AM UTC-8, Mat wrote:
Mohammad wrote:
Drag and drop in tiddlywiki.com and see how amazingly it works!

Thanks, both of you, for sharing. Please note that recursions can cause problems also: For example, go to tiddlywiki.com and tag the HelloThere tiddler with "Examples" (i.e to create a loop because Examples is a subtiddler to HelloThere). This does not cause problems. But if you add Mohammads creation you get RSOE. I'm not sure how native TW avoids this but know it was something that was actively dealt with a few years back.

This was one of my earlier TW5 contributions.  The TOC macros use an "exclude" paramter that is dynamically updated as the recursion occurs.  Each level of recursion adds the current Tiddler to a list (using syntax -[[tiddlername]]) so that as it dives down into the tree, any tiddler that has already been visited in the current 'branch' is excluded from being visited again.  This prevents infinite loops that eat up all the browser memory and eventually cause a fatal error condition. 

A wish: One major lacking feature of current ToC's is drag'n drop-ability. I.e to rearrange the branches in the tree. This would be the basis for a super useful outliner: The next step would be a feature to "open all tiddlers" in a tree or a subbranch. It'd be a very powerful tool for authoring longer texts.

My custom TOC macros for InsideTiddlyWiki include drag-and-drop handling.  To try it, open http://www.TiddlyTools.com/InsideTW and then 'unlock' the document (padlock icon in the upper right toolbar).  Then open the TOC "slidebar" (menu icon in the upper left toolbar).  Then just drag-n-drop items.  It supports "drop before", "drop after" and "drop into" handling based on modifier keys (default=drop before, SHIFT=drop after, CTRL=drop into).  The macro code is here: http://tiddlytools.com/InsideTW/#TiddlyTools%2FTOC%2FMacros.  See also http://tiddlytools.com/InsideTW/#TiddlyTools%2FTOC%2FTemplate and http://tiddlytools.com/InsideTW/#TiddlyTools%2FTOC%2FStylesheet


-e


-e

Mohammad

unread,
Jan 22, 2020, 7:44:03 AM1/22/20
to TiddlyWiki
Hi Mat,


On Wednesday, January 22, 2020 at 1:02:03 PM UTC+3:30, Mat wrote:
Mohammad wrote:
Drag and drop in tiddlywiki.com and see how amazingly it works!


Thanks, both of you, for sharing. Please note that recursions can cause problems also: For example, go to tiddlywiki.com and tag the HelloThere tiddler with "Examples" (i.e to create a loop because Examples is a subtiddler to HelloThere). This does not cause problems. But if you add Mohammads creation you get RSOE. I'm not sure how native TW avoids this but know it was something that was actively dealt with a few years back.

This is a very smart catch of error!

1. What we should do?
I need to prevent circular reference cause infinite recursion! So, the code should go to some depth for example 5 or 10 or higher levels, after that macro should stop recursion and show an alert!
I will try to address this.

2. Is circular reference is organic?
NO, assume chapter A has three sections: Aa, Ab, Ac, are listed along with itself in a toc. THEN, chapter A itself is a section of Ab! It doesn't make sense!
The toc in the core should ignore something which is a convention and it cannot solve the circular references!

So, in my opinion a circular reference is bad organization of content in wiki and should be avoided!

 

A wish: One major lacking feature of current ToC's is drag'n drop-ability. I.e to rearrange the branches in the tree. This would be the basis for a super useful outliner: The next step would be a feature to "open all tiddlers" in a tree or a subbranch. It'd be a very powerful tool for authoring longer texts.

<:-)

Cheers
Mohammad 

Mohammad

unread,
Jan 22, 2020, 7:56:24 AM1/22/20
to TiddlyWiki
Hi Eric,
 Many thanks for clarification and sharing that powerful toc macros!


On Wednesday, January 22, 2020 at 4:08:28 PM UTC+3:30, Eric Shulman wrote:
On Wednesday, January 22, 2020 at 1:32:03 AM UTC-8, Mat wrote:
Mohammad wrote:
Drag and drop in tiddlywiki.com and see how amazingly it works!

Thanks, both of you, for sharing. Please note that recursions can cause problems also: For example, go to tiddlywiki.com and tag the HelloThere tiddler with "Examples" (i.e to create a loop because Examples is a subtiddler to HelloThere). This does not cause problems. But if you add Mohammads creation you get RSOE. I'm not sure how native TW avoids this but know it was something that was actively dealt with a few years back.

This was one of my earlier TW5 contributions.  The TOC macros use an "exclude" paramter that is dynamically updated as the recursion occurs.  Each level of recursion adds the current Tiddler to a list (using syntax -[[tiddlername]]) so that as it dives down into the tree, any tiddler that has already been visited in the current 'branch' is excluded from being visited again.  This prevents infinite loops that eat up all the browser memory and eventually cause a fatal error condition. 

So, this is kind of convention! as circular references are organically not possible!
That means a grand father of x is the sun of x also!

But as you described, toc macro, if find A in the tree, it will ignore it in branches or sub branches

That is why if HelloThere is tagged with Examples, it is not appeared again under Examples branch in Table-of-Contents!


 

A wish: One major lacking feature of current ToC's is drag'n drop-ability. I.e to rearrange the branches in the tree. This would be the basis for a super useful outliner: The next step would be a feature to "open all tiddlers" in a tree or a subbranch. It'd be a very powerful tool for authoring longer texts.

My custom TOC macros for InsideTiddlyWiki include drag-and-drop handling.  To try it, open http://www.TiddlyTools.com/InsideTW and then 'unlock' the document (padlock icon in the upper right toolbar).  Then open the TOC "slidebar" (menu icon in the upper left toolbar).  Then just drag-n-drop items.  It supports "drop before", "drop after" and "drop into" handling based on modifier keys (default=drop before, SHIFT=drop after, CTRL=drop into).  The macro code is here: http://tiddlytools.com/InsideTW/#TiddlyTools%2FTOC%2FMacros.  See also http://tiddlytools.com/InsideTW/#TiddlyTools%2FTOC%2FTemplate and http://tiddlytools.com/InsideTW/#TiddlyTools%2FTOC%2FStylesheet


-e


-e


Cheers
Mohammad 

Eric Shulman

unread,
Jan 22, 2020, 7:59:30 AM1/22/20
to TiddlyWiki
Here's a very simple recursive "tree walk" that shows the entire TableOfContents tree:

\define toc-all(here,exclude)
<$list filter="""[title[$here$]tagging[]] $exclude$ -[[$here$]]""">
   
<$text text=<<currentTiddler>>/>
   <div style="padding-left:2em;">
       <$macrocall $name="toc-all" here=<<currentTiddler>> exclude="""$exclude$ -[[$here$]]"""/
>
   
</div>
</
$list>
\end

<<toc-all TableOfContents>>

Note that it does NOT require multiple macros to do the recursion, and uses the dynamically updated "exclude" param to avoid infinite loops.

enjoy,
-e

Mohammad

unread,
Jan 22, 2020, 8:00:26 AM1/22/20
to TiddlyWiki


On Wednesday, January 22, 2020 at 1:02:03 PM UTC+3:30, Mat wrote:
Mohammad wrote:
Drag and drop in tiddlywiki.com and see how amazingly it works!


Thanks, both of you, for sharing. Please note that recursions can cause problems also: For example, go to tiddlywiki.com and tag the HelloThere tiddler with "Examples" (i.e to create a loop because Examples is a subtiddler to HelloThere). This does not cause problems. But if you add Mohammads creation you get RSOE. I'm not sure how native TW avoids this but know it was something that was actively dealt with a few years back.

Mat, I will go with the solution Eric provided!
ignore a title if it has been processes earlier in the tree! What do you think!

--Mohammad 

Mat

unread,
Jan 22, 2020, 9:10:26 AM1/22/20
to TiddlyWiki
Eric Shulman wrote:
My custom TOC macros for InsideTiddlyWiki include drag-and-drop handling.  To try it, open http://www.TiddlyTools.com/InsideTW and 

Aha! 
It has an on-hover "more button" showing tools.
And it auto-navigates to show where in the tree you are!
I'm not sure how to test if it is possible to drag'n drop a tiddler title from the river into the ToC - is it?

Really cool Eric, I'll start using it!!! 

<:-) 

Mohammad

unread,
Jan 22, 2020, 10:23:44 AM1/22/20
to TiddlyWiki
Amazing Eric!

How keep this simple and add the expandable behavior on node with child branches?

Mohammad

unread,
Jan 22, 2020, 10:25:00 AM1/22/20
to TiddlyWiki
Eric,
Is it possible to have this toc macro in our wiki? if yes how?
 
-e


-e

Eric Shulman

unread,
Jan 22, 2020, 10:25:06 AM1/22/20
to TiddlyWiki
On Wednesday, January 22, 2020 at 6:10:26 AM UTC-8, Mat wrote:
Eric Shulman wrote:
My custom TOC macros for InsideTiddlyWiki include drag-and-drop handling.  To try it, open http://www.TiddlyTools.com/InsideTW and 

Aha! 
It has an on-hover "more button" showing tools.

Yes... this makes it easy to use "New Here" to add a new child item to the tree

And it auto-navigates to show where in the tree you are!

It uses $:/HistoryList!!currenttiddler to highlight the most recently opened tiddler

I'm not sure how to test if it is possible to drag'n drop a tiddler title from the river into the ToC - is it?

It is.  Normal tiddler title dragging sets the "actionTiddler" drag value to the tiddler title.  My TOC drag-n-drop handling uses the same convention, so that dragging a tiddler title from the river works.  The only difference is that the "drop prompt" display doesn't report the name of the tiddler being dragged... but it DOES work.
 
Really cool Eric, I'll start using it!!! 

enjoy,
-e 

Mohammad

unread,
Jan 22, 2020, 10:36:42 AM1/22/20
to TiddlyWiki
Eric,
 In your solution, how one can EXCLUDE one branch or item from toc?
I means assume in tiddlywiki.com I want to exclude (hide) Examples branch from!
How the below code should be modified to reflect this exclusion?

--Mohammad

Eric Shulman

unread,
Jan 22, 2020, 11:10:06 AM1/22/20
to tiddl...@googlegroups.com
On Wednesday, January 22, 2020 at 7:36:42 AM UTC-8, Mohammad wrote:
 In your solution, how one can EXCLUDE one branch or item from toc?
I means assume in tiddlywiki.com I want to exclude (hide) Examples branch from!
How the below code should be modified to reflect this exclusion?

When you *invoke* the macro, just add a pre-defined value for the "exclude" parameter, like this:

<<toc-all TableOfContents "-[[Examples]]">>

Note that you can exclude multiple branches if you want.  E.g.:

<<toc-all TableOfContents "-[[Examples]] -[[Filter Examples]] -[[Macro Examples]] -[[Variable Examples]] -[[Widget Examples]] -[[WikiText Examples]]">>

enjoy,
-e

Eric Shulman

unread,
Jan 22, 2020, 11:29:08 AM1/22/20
to TiddlyWiki
On Wednesday, January 22, 2020 at 7:25:06 AM UTC-8, Eric Shulman wrote:
And it auto-navigates to show where in the tree you are!

It uses $:/HistoryList!!currenttiddler to highlight the most recently opened tiddler

I just made a small fix to the TOC/Template to restore the use of <$scrollhere> (see TiddlyTools/TOC/scrollhere.js)

What this does is ensure that the highlighted TOC item (i.e., the most recently displayed tiddler) is always visibly displayed in the TOC.

For InsideTW, this occurs if you have fully expanded the TOC list (click the double-down-chevron in the upper left corner of the TOC slidebar).  Since the TOC slidebar has a fixed height, the fully expanded TOC list will result in a scrollbar.  If you click a link in the body text that navigates to a tiddler that is listed below the current visible TOC, the <$scrollhere> macro forces the slidebar TOC to scroll that tiddler into view.

Also, note that my TOC macros include handling to "auto-open" a branch when you navigate to the branch "root" or if you use a body text link to navigate to a tiddler in a branch that is not currently opened.

The combine result of auto open and scroll here ensures that "no matter where you go, there you are" (* see "Buckaroo Bonzai through the 8th Dimension" https://www.youtube.com/watch?v=jv_jkju_iZg)

-e

Mohammad

unread,
Jan 22, 2020, 1:22:04 PM1/22/20
to TiddlyWiki
Thanks! It works!
This address the long waiting exclude branches, nodes in toc macro included in the core!

Scott Kingery

unread,
Jan 22, 2020, 1:36:01 PM1/22/20
to TiddlyWiki
Thanks all for the work on this.

Mohammad, I like that you are hiding the > symbols for entries that don't have sub-entries. However, this doesn't seem to work in my testing when the top level has no sub-entries. For example, if on tiddlywiki.com there were no HelloThere entries you would still get the ">" symbol. Not sure if that is fixable.

Scott

Mohammad Rahmani

unread,
Jan 22, 2020, 1:44:01 PM1/22/20
to tiddl...@googlegroups.com
Hi Scott!
 Sure I will fix it! By the way I may recommend to have a look at the solutions provided by Eric.

--Mohammad


Best wishes
Mohammad


--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/22548730-53e5-40ea-a201-4ca46d447c95%40googlegroups.com.

Mohammad Rahmani

unread,
Jan 22, 2020, 1:54:14 PM1/22/20
to tiddl...@googlegroups.com
Scott,
 I cannot reproduce it!
I deleted HelloThere and even TableOfContents, it works fine.
Could give me a short a example!


Best wishes
Mohammad


On Wed, Jan 22, 2020 at 10:06 PM Scott Kingery <techlif...@gmail.com> wrote:

Mat

unread,
Jan 22, 2020, 2:09:44 PM1/22/20
to TiddlyWiki
Eric, I'm trying out your TOC. A few issues.

First, for reference, here's a complete list of all tiddlers:

http://tiddlytools.com/InsideTW/#TiddlyTools%2FTOC%2FMacros 
http://tiddlytools.com/InsideTW/#TiddlyTools%2FTOC%2FTemplate 
http://tiddlytools.com/InsideTW/#TiddlyTools%2FTOC%2FStylesheet 
http://tiddlytools.com/InsideTW/#TiddlyTools%2FTOC%2Fscrollhere.js

I copied these and put them up here: http://els-toc.tiddlyspot.com/

Problems:

Drag'n dropping a toc item creates double entries.
The icons for open/close to the left of each item can't be seen. I've searched but can't figure out why. 

Anyone else experiencing this? Any help would be appreciated.

<:-)

Scott Kingery

unread,
Jan 22, 2020, 2:21:11 PM1/22/20
to TiddlyWiki
Mohammad,
That's odd, it is instantly reproducible for me.

in Tiddlywiki.com:
Create a new tiddler
Tag it "TabelOfContents"
Drag in your Tony-TOC-Expandable 5 tiddler
See the results

Unless you've updated your code since then.

Looks like the attached for me.
Scott


On Wednesday, January 22, 2020 at 10:54:14 AM UTC-8, Mohammad wrote:
Scott,
 I cannot reproduce it!
I deleted HelloThere and even TableOfContents, it works fine.
Could give me a short a example!


Best wishes
Mohammad


On Wed, Jan 22, 2020 at 10:06 PM Scott Kingery <techlif...@gmail.com> wrote:
Thanks all for the work on this.

Mohammad, I like that you are hiding the > symbols for entries that don't have sub-entries. However, this doesn't seem to work in my testing when the top level has no sub-entries. For example, if on tiddlywiki.com there were no HelloThere entries you would still get the ">" symbol. Not sure if that is fixable.

Scott

On Tuesday, January 21, 2020 at 9:21:34 PM UTC-8, Mohammad wrote:
Hi Tony,
 
This is an improved TOC-Expandable sports two button to collapse and expand all tiddlers in the table-of-contents
Also it is smart enough to hide the right arow for entries have no child.

I have created an experimental wiki on tiddlyspot will share later.

Drag and drop in tiddlywiki.com and see how amazingly it works!

toc-expandable-fig01.png



toc-expandable-fig02.png


--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddl...@googlegroups.com.
tocdemo.png

Mohammad

unread,
Jan 22, 2020, 3:11:15 PM1/22/20
to TiddlyWiki
Hi Scott,
 Yea, you are right the first level entries show the > even if has no child!
I will correct and upload again!

--Mohammad

Mohammad

unread,
Jan 22, 2020, 3:21:08 PM1/22/20
to TiddlyWiki
Hi Scott,
 Try the attached revised TOC.
I confirm that the Eric method is simpler and takes care of circular references!
I may add the selective-expandable feature to it!

Note that you can customize the code to meet your requirements.

--Mohammad

On Wednesday, January 22, 2020 at 10:51:11 PM UTC+3:30, Scott Kingery wrote:
Tony-TOC-Expandable 6.tid

Scott Kingery

unread,
Jan 22, 2020, 4:41:14 PM1/22/20
to TiddlyWiki
Thanks, Mohammad. I can confirm it works. I'll have a look at Eric's solution as well.

Scott

Eric Shulman

unread,
Jan 22, 2020, 4:45:27 PM1/22/20
to TiddlyWiki
On Wednesday, January 22, 2020 at 11:09:44 AM UTC-8, Mat wrote:
Drag'n dropping a toc item creates double entries.

I wrote these macros for my TiddlyBook framework which is used by InsideTW.  As a consequence, there are some TiddlyBook-specific dependencies that you need to satisfy.

Specifically, the <<toc-show-item>> macro is displaying ALL entries twice because it depends on the definitions of the .readertools and .authortools CSS classes, which are found in
   TiddlyTools/ReadOnly/Stylesheet

These classes are used throughout the TiddlyBook framework to enable alternative output based on the setting contained in $:/config/TiddlyTools/ReadOnly.  If that config tiddler contains "yes", then you get "read-only" TOC displays (which bypasses the drag-and-drop handling).  If that config tiddler contains anything else (or doesn't exist) then you get the full "authoring" TOC display, which includes drag-and-drop handling and the on-hover "more" menu.

Thus, to eliminate the doubled TOC entry display, import TiddlyTools/ReadOnly/Stylesheet into your document.  As soon as you do that, each TOC entry will be displayed just once, as intended.

The icons for open/close to the left of each item can't be seen. I've searched but can't figure out why. 

As the name implies, the <<toc-all>> macro is not supposed to show open/close arrows... it ALWAYS shows ALL items in the tree.

If you want to be able to toggle the tree branches, use <<toc-tree>> instead of <<toc-all>>.  You will then see the open/close arrows next to branches that have children.  The state flags that control which branches are currently open are stored in $:/config/TiddlyTools/TOC.  If you want to open all tree branches at once, put the <<toc-toggle-all>> macro somewhere in your content.  This macro displays a button that toggles the "OpenAll" state flag in $:/config/TiddlyTools/TOC.

That should take care of the two problems you reported.  Let me know how it goes...

enjoy,
-e

Eric Shulman

unread,
Jan 22, 2020, 4:59:28 PM1/22/20
to TiddlyWiki
On Wednesday, January 22, 2020 at 12:21:08 PM UTC-8, Mohammad wrote:
I confirm that the Eric method is simpler and takes care of circular references!

Please note that Jeremy added this to the TWCore TOC definitions ($:/core/macros/toc) a long time ago.  However, there is one difference...

The exclude value in my original solution uses "-[[TiddlerName1]] -[[TiddlerName2]] ..." in the "exclude" parameter to remove the circular references from the recursion.

When Jeremy adapted my solution to the TWCore, he changed the usage of the exclude parameter to contain a plain list of tiddler names (e.g., TiddlerName1 TiddlerName2 ...) which he then uses in the filter as "-[enlist<__exclude__>]".

(When I first created this solution years ago, there was no "enlist" operator, so I had to append each excluded title separately, as show above)

-e 

TonyM

unread,
Jan 22, 2020, 6:07:35 PM1/22/20
to TiddlyWiki
Eric, et al

A lot has happened overnight (my time) in this thread.

Thanks for your contributions, and eric for this example

\define toc-all(here,exclude)
<$list filter="""[title[$here$]tagging[]] $exclude$ -[[$here$]]""">
   
<$text text=<<currentTiddler>>/>
   <div style="padding-left:2em;">
       <$macrocall $name="toc-all" here=<<currentTiddler>> exclude="""$exclude$ -[[$here$]]"""/
>
   
</div>
</
$list>
\end

<<toc-all TableOfContents>>

It is important to share the single  macro version; the reason  I did not earlier is to leave the ability to standardise a heading before the TOC is rendered.

This is an elegant way to to track the branch and combat loops, thanks. 

One reason I have not published a TOC with loop prevention so far is I am keen to build more smarts into the the branch handling mechanism, such as showing relationships, capturing the branch separately from the tree that generates it (snapshot toc) and more. 

However It would be nice to build this loop prevention into the First example given while retaining access to insert customisations we see subsequently published.

I am keen to have the concept of recursion becomes better known in the community.


 

bimlas

unread,
Jan 23, 2020, 7:43:27 AM1/23/20
to TiddlyWiki
Eric,


It has an on-hover "more button" showing tools.

Yes... this makes it easy to use "New Here" to add a new child item to the tree

In my opinion, this solution is not really usable on the phone (although I have only tried it in DeveloperTools Responsive view), because hover is only possible with the mouse.

I created this plugin for a similar purpose: https://bimlas.gitlab.io/tw5-override-navigation/

In this case, the "toolbar buttons" do not appear next to the link, but, for example, between the page controll buttons (or where you just placed them) and operate with any link (not just the ToC elements).

Mohammad

unread,
Jan 23, 2020, 4:33:24 PM1/23/20
to TiddlyWiki
Eric,
 I could successfully install the Tiddlytools/TOC on tiddlywiki.com
 It seems it is slow as I click on an entry or a link (update the currentTiddler) 

I use toc-tree. How I can overcome the very slow performance?

--Mohammad

Eric Shulman

unread,
Jan 23, 2020, 11:05:10 PM1/23/20
to TiddlyWiki
On Thursday, January 23, 2020 at 4:43:27 AM UTC-8, bimlas wrote:
Eric,

It has an on-hover "more button" showing tools.

Yes... this makes it easy to use "New Here" to add a new child item to the tree

In my opinion, this solution is not really usable on the phone (although I have only tried it in DeveloperTools Responsive view), because hover is only possible with the mouse.

I created my custom TOC (and associated styles) for use in my TiddlyBook framework.  The expectation is that *authoring* activities would occur on a fully-capable platform (e.g., a desktop system), while *reading* activities could occur on both desktop and mobile platforms.   In the TOC, the "hide until hover" styles are applied to both the "more" (down arrow) menu button and the "toggle favorite" (star) buttons.  This was done to reduce visual clutter.  Note that both of these buttons are also available, *without hovering*, directly in the titlebar of the currently displayed tiddler, so it's not as if the TOC display is the ONLY way to access these functions.

Nonetheless, there is an easy modification that will bypass the "hide until hover" behaviors for the TOC buttons.  All you need to do is to re-define the default (non-hovering) "opacity:0.0" styles for these buttons.

Create a stylesheet tiddler (tagged with $:/tags/Stylesheet) containing:
.tt-toc-item .tt-favorite  { opacity:0.5; }
.tt-toc-item .tt-toc-tools { opacity:0.5; }

That's all you need to do to make those buttons available on a mobile (non-hovering) platform.

enjoy,
-e

Mohammad

unread,
Jan 24, 2020, 7:25:23 AM1/24/20
to tiddl...@googlegroups.com
Eric,
 It seems drag onto works fine (using ctrl)
 but drag after and before does not work. Always the dropped item appended to the end of list.
 This prevent to reorder items in a branch.

 Would you please check it?

Mohammad

unread,
Jan 24, 2020, 11:00:30 PM1/24/20
to TiddlyWiki
Problem with drag and drop in the author mode:  http://www.TiddlyTools.com/InsideTW

Hi Eric,

 I think I understood what is wrong with toc-tree in author mode!
It seems in TiddlyTools/TOC/Macros

the line

<$action-listops $tiddler=<<newtag>> $field="list" $subfilter="+[append<actionTiddler>putafter<item>]" />



does not work on empty list or when the list field is not existed! It may be related to append.

To reproduce the issue goto  http://www.TiddlyTools.com/InsideTW
create the below set of tiddlers
A, B both tagged with root
aa, ab, ac all tagged with A
ba, bb, bc all tagged with B

then in a new tiddler:

<<toc-toggle-all>>

<
<toc-tree "root">>

Now in author mode, try to drag and drop children in the same branch or other branch.
Only drag onto (ctrl+drop) works!

Now using the tag pill of A and B reorder tiddlers cause to create list field with children in A, and B.
Repeat drag and drop! It works now!

Mohammad

unread,
Jan 24, 2020, 11:34:46 PM1/24/20
to TiddlyWiki
Eric,

Another issue:

In the example of previous post assume you add a new tiddler tagged with A named ad
If ad has a list-after field with value aa, whenever you reorder list and darg and drop aa to a new position, dd will be moved and appear after aa.
the same is true for child tiddlers with list-before field.


--Mohammad

Eric Shulman

unread,
Jan 25, 2020, 12:44:16 AM1/25/20
to TiddlyWiki
On Friday, January 24, 2020 at 8:34:46 PM UTC-8, Mohammad wrote:
In the example of previous post assume you add a new tiddler tagged with A named ad
If ad has a list-after field with value aa, whenever you reorder list and darg and drop aa to a new position, dd will be moved and appear after aa.
the same is true for child tiddlers with list-before field.

I think both of these issues (the missing/empty list, and the use of list-before/list-after) need additional code in the drop handler to force the desired result.  Something similar to what is done in the $:/core/macros/list drop handler, where it gets the current order of the tagged items (even if there is no list field), clears all list-before/list-after fields, and then builds an appropriate list field in the target tag:

\define list-tagged-draggable-drop-actions(tag)
<!-- Save the current ordering of the tiddlers with this tag -->
<$set name="order" filter="[<__tag__>tagging[]]">
<!-- Remove any list-after or list-before fields from the tiddlers with this tag -->
<$list filter="[<__tag__>tagging[]]">
<$action-deletefield $field="list-before"/>
<$action-deletefield $field="list-after"/>
</$list>
<!-- Save the new order to the Tag Tiddler -->
<$action-listops $tiddler=<<__tag__>> $field="list" $filter="+[enlist<order>] +[insertbefore:currentTiddler<actionTiddler>]"/
>
<!-- Make sure the newly added item has the right tag -->
<!-- Removing this line makes dragging tags within the dropdown work as intended -->
<!--<$action-listops $tiddler=<<actionTiddler>> $tags=<<__tag__>>/>-->
<!-- Using the following 5 lines as replacement makes dragging titles from outside into the dropdown apply the tag -->
<$list filter="[<actionTiddler>!contains:tags<__tag__>]">
<$fieldmangler tiddler=<<actionTiddler>>>
<$action-sendmessage $message="tm-add-tag" $param=<<__tag__>>/
>
</$fieldmangler>
</
$list>
</$set>
\end

I'll work on it over the next few days...

-e

Mohammad

unread,
Jan 25, 2020, 4:33:57 AM1/25/20
to TiddlyWiki
Hello again Eric,
Based on your recent reply, I made some change to toc-item-drop macro the and it seems it work now!
Please have a look and let me know if you confirm it.

--Mohammad


\define toc-item-drop()
<$reveal default=<<actionTiddler>> type="nomatch" text=<<item>>> <!-- DON'T DROP ON SELF -->
   <!-- get OLDTAG and NEWTAG, exclude special TiddlyBook tags -->
   <$vars sourcetags={{{ [<actionTiddler>get[tags]] }}}
          targettags={{{ [<item>get[tags]] }}}>
   <$vars oldtag={{{ [enlist<sourcetags>!enlist<toc-ignore-tags>] }}}
          newtag={{{ [enlist<targettags>!enlist<toc-ignore-tags>] }}}>
<!-- Save the current ordering of the tiddlers with this tag -->
<$set name="order" filter="[<newtag>tagging[]]">
<!-- Remove any list-after or list-before fields from the tiddlers with this tag -->
<$list filter="[<newtag>tagging[]]">
<$action-deletefield $field="list-before"/>
<$action-deletefield $field="list-after"/>
</$list>
   <$reveal default=<<modifier>> type="match" text="normal"> <!-- DROP BEFORE SIBLING -->
      <$action-listops $tiddler=<<actionTiddler>> $field="tags" $subfilter="-[<oldtag>]" />
      <$action-listops $tiddler=<<actionTiddler>> $field="tags" $subfilter="[<newtag>]" />
      <$action-listops $tiddler=<<oldtag>>        $field="list" $subfilter="-[<actionTiddler>]" />
      <$action-listops $tiddler=<<newtag>>        $field="list" $subfilter="+[enlist<order>] +[append<actionTiddler>putbefore<item>]" />
   </$reveal>
   <$reveal default=<<modifier>> type="match" text="shift"> <!-- DROP AFTER SIBLING -->
      <$action-listops $tiddler=<<actionTiddler>> $field="tags" $subfilter="-[<oldtag>]" />
      <$action-listops $tiddler=<<actionTiddler>> $field="tags" $subfilter="[<newtag>]" />
      <$action-listops $tiddler=<<oldtag>>        $field="list" $subfilter="-[<actionTiddler>]" />
      <$action-listops $tiddler=<<newtag>>        $field="list" $subfilter="+[enlist<order>] +[append<actionTiddler>putafter<item>]" />
   </$reveal>
   <$reveal default=<<modifier>> type="match" text="ctrl"> <!-- DROP AS CHILD -->
      <$action-listops $tiddler=<<actionTiddler>> $field="tags" $subfilter="-[<oldtag>]" />
      <$action-listops $tiddler=<<actionTiddler>> $field="tags" $subfilter="[<item>]" />
      <$action-listops $tiddler=<<oldtag>>        $field="list" $subfilter="-[<actionTiddler>]" />
      <$action-listops $tiddler=<<item>>          $field="list" $subfilter="[<actionTiddler>]" />
   </$reveal>
</$set>
   </$vars>
   </$vars>
</$reveal>
\end


Eric Shulman

unread,
Jan 25, 2020, 6:57:07 AM1/25/20
to TiddlyWiki
On Saturday, January 25, 2020 at 1:33:57 AM UTC-8, Mohammad wrote:
Hello again Eric,
Based on your recent reply, I made some change to toc-item-drop macro the and it seems it work now!
Please have a look and let me know if you confirm it.

Good Work!

However... it needed a little bit of tweaking...

* "drop after" wasn't working
* only do "list-before/list-after" fixups for "drop before" and "drop after" (not "drop into")

Here's my updated code (which has been uploaded to http://www.TiddlyTools.com/InsideTW)
\define toc-item-drop()
<$reveal default=<<actionTiddler>> type="nomatch" text=<<item>>> <!-- DON
'T DROP ON SELF -->

   <!-- get OLDTAG and NEWTAG, exclude special TiddlyBook tags -->
   <$vars sourcetags={{{ [<actionTiddler>get[tags]] }}}
          targettags={{{ [<item>get[tags]] }}}>
   <$vars oldtag={{{ [enlist<sourcetags>!enlist<toc-ignore-tags>] }}}
          newtag={{{ [enlist<targettags>!enlist<toc-ignore-tags>] }}}>
   <$reveal default=<<modifier>> type="match" text="normal"> <!-- DROP BEFORE SIBLING -->
      <$set name="order" filter="[<newtag>tagging[]]">
      <$list filter=<<order>>> <$action-deletefield $field="list-before"/> <$action-deletefield $field="list-after"/> </$list>

      <$action-listops $tiddler=<<actionTiddler>> $field="tags" $subfilter="-[<oldtag>]" />
      <$action-listops $tiddler=<<actionTiddler>> $field="tags" $subfilter="[<newtag>]" />
      <$action-listops $tiddler=<<oldtag>>        $field="list" $subfilter="-[<actionTiddler>]" />
      <$action-listops $tiddler=<<newtag>>        $field="list" $subfilter="[enlist<order>] -[<actionTiddler>] +[append<actionTiddler>putbefore<item>]" />
      </$set>

   </$reveal>
   <$reveal default=<<modifier>> type="match" text="shift"> <!-- DROP AFTER SIBLING -->
      <$set name="order" filter="[<newtag>tagging[]]">
      <$list filter=<<order>>> <$action-deletefield $field="list-before"/> <$action-deletefield $field="list-after"/> </$list>

      <$action-listops $tiddler=<<actionTiddler>> $field="tags" $subfilter="-[<oldtag>]" />
      <$action-listops $tiddler=<<actionTiddler>> $field="tags" $subfilter="[<newtag>]" />
      <$action-listops $tiddler=<<oldtag>>        $field="list" $subfilter="-[<actionTiddler>]" />
      <$action-listops $tiddler=<<newtag>>        $field="list" $subfilter="[enlist<order>] -[<actionTiddler>] +[append<actionTiddler>putafter<item>]" />
      </$set>

   </$reveal>
   <$reveal default=<<modifier>> type="match" text="ctrl"> <!-- DROP AS CHILD -->
      <$action-listops $tiddler=<<actionTiddler>> $field="tags" $subfilter="-[<oldtag>]" />
      <$action-listops $tiddler=<<actionTiddler>> $field="tags" $subfilter="[<item>]" />
      <$action-listops $tiddler=<<oldtag>>        $field="list" $subfilter="-[<actionTiddler>]" />
      <$action-listops $tiddler=<<item>>          $field="list" $subfilter="[<actionTiddler>]" />
   </$reveal>
   </$vars>
   </$vars>
</$reveal>
\end

Notes:
* To make "drop after" work, it was necessary to first *remove* the actionTiddler from the list, and then re-add it
* The "[enlist<order>]" didn't need a leading "+", since it will, by definition, override all previous ordering in the list
* Strictly speaking, clearing the list-before/list-after *could* be skipped, allowing items to remain "locked" into a specific sequence.  However, since the effective ordering is preserved by the [enlist<order>], its OK to clear list-before/list-after, and "unlocking" the list ordering is probably more intuitive overall.

Thank you VERY much for your help.  You saved me quite a bit of experimentation and debugging!  Great bit of collaborative effort here!

-e

Mohammad

unread,
Jan 25, 2020, 9:14:37 AM1/25/20
to TiddlyWiki
Hi Eric,
 Thank you for update.

--Mohammad

Mohammad

unread,
Feb 17, 2020, 4:23:46 PM2/17/20
to TiddlyWiki
Hi,

Based on the discussion here, I have made a small two level non recursive TOC generator which is rather fast andn most cases
is enough for simple small wikis. It uses simple navigation buttons as tiddler footer.


--Mohammad

On Wednesday, January 22, 2020 at 1:02:03 PM UTC+3:30, Mat wrote:
Mohammad wrote:
Drag and drop in tiddlywiki.com and see how amazingly it works!


Thanks, both of you, for sharing. Please note that recursions can cause problems also: For example, go to tiddlywiki.com and tag the HelloThere tiddler with "Examples" (i.e to create a loop because Examples is a subtiddler to HelloThere). This does not cause problems. But if you add Mohammads creation you get RSOE. I'm not sure how native TW avoids this but know it was something that was actively dealt with a few years back.

A wish: One major lacking feature of current ToC's is drag'n drop-ability. I.e to rearrange the branches in the tree. This would be the basis for a super useful outliner: The next step would be a feature to "open all tiddlers" in a tree or a subbranch. It'd be a very powerful tool for authoring longer texts.

<:-)
Reply all
Reply to author
Forward
0 new messages