TW5 Exporting Tiddlers in the TOC order

111 views
Skip to first unread message

Martin Hochstrasser

unread,
May 3, 2016, 3:15:01 AM5/3/16
to TiddlyWiki
Hi all,

Since I love TiddlyWiki (and hacking it a bit) and I recently had to write a spec for our REST API, I thought it would be a good idea to write it in TiddlyWiki for all the goodness of structure, SVG diagrams and the like.

Now a client needs the spec, and he's a bit on the conservative side; read: he wants docx or pdf.

I tried export all, but this sorts the tiddlers by title, so the structure's gone.

Now I'd like to export all tiddlers in the order appearance of the <<toc>> macro to a static html for converting to PDF.

Could someone please help me how to do this, or point me in the right direction?

I tried copying the <<toc>> macro to my tiddlers and transclude the tiddler text, but this didn't work out. I can't seem to grasp this macro/widget thing...

Best regards,
Martin


Evolena

unread,
May 3, 2016, 4:33:36 AM5/3/16
to tiddl...@googlegroups.com
Hello Martin,

Here is my approach:
I've tweaked the toc macro to populate the "list" field of a tiddler (TOC-export) with each tiddler instead of displaying its title.
As I use an action widget, I have encapsulated the call of this macro inside a button, in the TOC-Export tiddler. Clicking the button populate the list field of the TOC-export tiddler with all tiddlers in the TableOfContents, in their order of appearance (however, if a tiddler appears several times in the TOC, it will be present only once in the list field).
Finally, in the advance search, I can use the [list[TOC-export]] filter to export the result in static HTML.

Here is the content of my TOC-export tiddler:

\define current() [[$(currentTiddler)$]]

\define toc-export(rootTag,tag,sort:"")
<$list filter="""[all[shadows+tiddlers]tag[$tag$]!has[draft.of]$sort$]""">
<$action-listops $tiddler="TOC-export" $field="list" $subfilter="+[append<current>]"/>
<$list filter="""[all[current]] -[[$rootTag$]]""">
<$macrocall $name="toc-export" tag=<<currentTiddler>> rootTag="""$rootTag$""" sort="""$sort$"""/>
</$list>
</
$list>
\end

<$button>
<<toc-export rootTag:"TableOfContents" tag:"TableOfContents">>
Export
</$button>

 There may be an easier way to pass the current tiddler to the action-listops widget, but using directly the <<currentTiddler>> variable results in each word of the current title being added independently into the list.

The call of the toc-export macro has both the rootTag and the tag parameter because I used the toc-body macro as a model, instead of the toc macro which only calls the toc-body macro to hide the rootTag parameter to the user.

Martin Hochstrasser

unread,
May 3, 2016, 4:57:44 AM5/3/16
to TiddlyWiki
Wow...

Thank you very much Evolena! I'll try this as soon as possible! 

Best regards,
Martin 

Martin Hochstrasser

unread,
May 3, 2016, 7:22:26 AM5/3/16
to TiddlyWiki
Works like a charm...

Thank you very much!
Reply all
Reply to author
Forward
0 new messages