Macro and Parameter Substitution

I have a macro to show some WikText! That means I need the wikified result.

Which form is the recommended one in TiddlyWiki?

i.

\define mymac(p)
<div class="some-class">
$p$
</div>
\end

ii.

\define mymac(p)
<div class="some-class">
<<__p__>>
</div>
\end

I may call mymac with attribute values like

<<mymac p:"
Hi TW

* One
* Two

">>

So, I need a block output and inline output based on the value passed to p. I do not like extra paragraphs generated (<p>..</p> in rendered output) which makes troubles with my css.

There is a problem in the TW parser, that produces redundant P tags. At the moment this behaviour cannot be prevented.

See: I Would Like to Fix the redundant P-tag Problem

If you use $p$, the parameter value is inserted directly into the macro output, before any rendering occurs. If the parameter value starts with a newline, the output will be rendered in block mode. If the parameter doesn’t start with a newline, the output will be rendered inline.

If you use <<__p__>>, the parameter value is handled as a variable that is processed during rendering. Since the <<__p__>> occurs inside a <div>...</div> wrapper that doesn’t start with a newline, it will always be rendered inline.

Thus, it seems that using $p$ is necessary if you want implicit handling of block vs input mode based on the presence of a leading newline in the macro parameter value. However, this doesn’t address your concerns about <p>...</p> wrappers in the rendered output, so you still may have issues with your CSS.

3 Likes

Thank you @EricShulman for the in details answer. So, for now and as far as the Fix for p-tag is not available. I should go with $p$.