Automatic ToC with PartTiddler and ForEach - Not working

7 views
Skip to first unread message

Jules

unread,
Mar 20, 2006, 8:02:05 AM3/20/06
to TiddlyWiki
Hi all, this is my first post. I've been trying TW for a couple of
weeks now and I am finding it VERY useful. I keep a number of TW
"notebooks" on my memory stick.

One thing I would really like to do though is have an automated Table
of Contents for longish tiddlers.

I thought that I would be able to use PartTiddler and ForEach to do
this as in this code:


!Example Table of Contents
<<forEachTiddler
where 'tiddler.title.contains("Sandbox/")'
write 'tiddler.title+"\n"'
>>

<part a1Part>
This is some text in a part.
</part>
<part a2Part hidden>
Another part with text
</part>

But this does not work as ForEach does not seem to recognise parts.

Does anyone know of a way around this?

Many thanks. J.

Daniel Baird

unread,
Mar 20, 2006, 8:29:20 AM3/20/06
to Tiddl...@googlegroups.com

Maybe it would be easier just to parse the tiddler for headings (either by looking for lines starting with a ! in the text, or <hN> elements in the rendered tiddler) and use those in your TOC.

Do you know much javascript Jules?  I suspect the parse-DOM-for-heading-elements thing would be pretty easy.

;Daniel
--
Daniel Baird
http://danielbaird.com (TiddlyW;nks! :: Whiteboard Koala :: Blog :: Things That Suck)
[[My webhost uptime is ~ 92%.. if no answer pls call again later!]]

Jules

unread,
Mar 20, 2006, 11:32:32 AM3/20/06
to TiddlyWiki
Hmm, my JS is rusty at best but it's mainly that I still don't have my
head around the complexity of the TW objects & don't have a lot of
spare time.

I was hoping for a short-cut to be honest.

I was surprised that the two tools didn't work together as they both
come from the same author. A development request maybe?

J.

Daniel Baird

unread,
Mar 20, 2006, 6:47:39 PM3/20/06
to Tiddl...@googlegroups.com

You might be blessed with a scrap from the coding gods.  There are people here who could knock this up in aboout 90 seconds.. the only problem is that they have a finite number of seconds to allocate ;)

I'll keep my fingers crossed..

;Daniel



On 21/03/06, Jules <kni...@googlemail.com> wrote:

Hmm, my JS is rusty at best but it's mainly that I still don't have my
head around the complexity of the TW objects & don't have a lot of
spare time.

I was hoping for a short-cut to be honest.






Udo Borkowski

unread,
Mar 20, 2006, 7:41:05 PM3/20/06
to Tiddl...@googlegroups.com
Actually I thought of making "Part tiddlers" be more like "normal" tiddlers (e.g. to iterate them in the forEachTiddler macro, or display them in the sidebar lists) but finally decided to leave them "2nd Class Tiddlers" because of performance reasons. This is because to find all "Parts" of a tiddler one needs to process the complete text of a tiddler. Even just to detect that a tiddler has no parts requires a complete parse of the tiddler. A full processing of every tiddler for every ForEachTiddler call would significantly slow down the performance of the ForEachTiddler macro.

Maybe introducing a "forEachPart" macro (that only works on the parts of a given tiddler) would be a useful alternative in the future, but this is not planned yet.

I therefore suggest that you use the approach proposed by Daniel to search the heading elements in the DOM and build the TOC from that. Maybe make this a plugin on its own, so it can easily reused. BTW: processing the DOM also has the advantage that you are not bound to the "Part" plugin.



Udo
Reply all
Reply to author
Forward
0 new messages