recursive javascript macro

79 views
Skip to first unread message

Laurent Bonet

unread,
Sep 3, 2018, 8:34:26 PM9/3/18
to TiddlyWiki
Hello all,

Trying to write a "recursive" javascript macro to generate nested list.

Anyone can help.

Do I have to more complex things (plugin?) to achieve such objective.

Thx in advance for your help.

Rgds

Laurent 

Capture d’écran 2018-09-04 à 02.22.17.png


TonyM

unread,
Sep 3, 2018, 9:28:40 PM9/3/18
to TiddlyWiki
Laurent,

I can't help you on the JavaScript but have you tried using recursion in WikiText as do the core toc macros ?

$:/core/macros/toc


TiddlyWiki via its wiki text/macros is really good at generating nested lists, it is also trivial I believe to pass the list items to a javascript macro so if you really must use Javascript consider a hybrid approach.

Regards
Tony

Eric Shulman

unread,
Sep 4, 2018, 1:18:23 AM9/4/18
to TiddlyWiki
On Monday, September 3, 2018 at 6:28:40 PM UTC-7, TonyM wrote:
Laurent,
I can't help you on the JavaScript but have you tried using recursion in WikiText as do the core toc macros ?

 

On Tuesday, September 4, 2018 at 10:34:26 AM UTC+10, Laurent Bonet wrote:

Trying to write a "recursive" javascript macro to generate nested list.

Here's your code, written using a blend of wikitext, widgets, and HTML :

\define recursiveBuild(root)
<li>$root$<ul>
<$list filter="[field:_compose[$root$]]">
   
<$macrocall $name="recursiveBuild" root=<<currentTiddler>> />
</
$list>
</ul></li>
\end

Put the above into a tiddler tagged with $:/tags/Macro, and then invoke it from any tiddler using:
<<recursiveBuild Foobar>>
(where Foobar is the name of the initial root tiddler)

let me know how it goes...

enjoy,
-e
Eric Shulman
TiddlyTools.com: "Small Tools for Big Ideas!" (tm)
InsideTiddlyWiki: The Missing Manuals

Laurent Bonet

unread,
Sep 4, 2018, 3:03:40 AM9/4/18
to TiddlyWiki
Thx very much for your reactivity. It works perfectly.

My first attempt was also with the $list widget but I mixed the order betwen <ul> and <li> resulting in a not well nested list ...
So I went to something much too complicated ... the only good point is that I learned how to write a javascript macro (and that you have to reload your page each time you make a modif on it).

Again thanks a lot !!!

Laurent

PS: I'm a new comer in Tiddlywiki but this piece of software looks really really powerfull, looks also that there id a great community community behind)
Reply all
Reply to author
Forward
0 new messages