--render is not including the replacement of global macros

49 views
Skip to first unread message

Soren Bjornstad

unread,
May 9, 2020, 9:55:58 PM5/9/20
to TiddlyWiki
Hi all,

I'm having a strange problem trying to render HTML with the Node --render command. As the subject says, the output of global macros doesn't show up. Yet local macros work fine. Am I doing something wrong, or is this a bug or just not supported this way? The documentation doesn't say anything about lack of support, and I would not expect content to be completely dropped from the rendered output without warning.

Here's a minimal test case:

created: 20200510013858423
modified
: 20200510013929749
tags
: $:/tags/Macro
title
: testmacro
type
: text/vnd.tiddlywiki
 
\define myglobalmacro() Some more nice text.

created: 20200510013706375
modified
: 20200510013934876
tags
:
title
: test2
type
: text/vnd.tiddlywiki
 
\define mymacro() Hello world!
 
<<mymacro>>
 
<<myglobalmacro>>
 
Signing off.

Within my wiki, as expected, this tiddler renders as:

<div class="tc-tiddler-body tc-reveal"><p>Hello world!</p><p>Some more nice text.</p><p>Signing off.</p></div>

On the other hand, when I run:

"$(npm bin)/tiddlywiki" --render '[[test2]]' "[is[tiddler]addsuffix[.html]]"

...in output/test2.html, I get merely:

<p>Hello world!</p><p>Signing off.</p>

My first thought was that TiddlyWiki filtered out the tiddler containing the macro, so it didn't know how to do the replacement. But then I tried:

"$(npm bin)/tiddlywiki" --render '[is[tiddler]]' "[is[tiddler]addsuffix[.html]]"

...and that didn't work either.

Any idea how I can get all my macros replaced properly? I'm actually trying to extract just the rendered portions of one global macro from my wiki this way, so having it skip rendering exactly the only part I care about is pretty ironic!

Soren Bjornstad

unread,
May 9, 2020, 10:30:46 PM5/9/20
to tiddl...@googlegroups.com
For kicks, I decided to try turning the macro tiddler into a template and rendering through that on the command line, and this worked. Viz., I added to the bottom of the testmacro tiddler:

<$transclude mode="block" />

Then ran:

"$(npm bin)/tiddlywiki" --render '[[test2]]' "[is[tiddler]addsuffix[.html]]" text/html "testmacro"

And now I got, as expected:

<p><p>Hello world!</p><p>Some more nice text.</p><p>Signing off.</p></p>

Obviously, this is a rather hacky "solution" to the problem, so while this will do for now for my use case, I'd still appreciate knowing if this is supposed to work, and perhaps a note in the documentation if it is not supposed to work.

Saq Imtiaz

unread,
May 10, 2020, 5:44:30 AM5/10/20
to TiddlyWiki
Hi Soren,

So in your first example of a render command, you aren't providing a template to render the tiddler through. So the actual content with no extra processing gets rendered.

Macros in TiddlyWiki are made available (or not) by the templates you use.

For example, note the third line in:

\import [[$:/core/ui/PageMacros]] [all[shadows+tiddlers]tag[$:/tags/Macro]!has[draft.of]]

You can place that in any template you use to render your tiddlers to make global macros available.

You will find that the same line appears in $:/core/ui/ViewTemplate as well.

Hope this helps,
Saq

Soren Bjornstad

unread,
May 10, 2020, 10:10:26 AM5/10/20
to TiddlyWiki
Saq,

Aha! This totally makes sense. Just a part of the rendering mechanism I've never had reason to look into. Thanks!
Reply all
Reply to author
Forward
0 new messages