Double quotes as terminators and its brethren

We can use " and “”" as terminators. This allows thing such as

<$button actions="""<$macrocall $name=showPart id="$partpartnum$" origin="$(host)$"/>""">see</$button>

But how can I find this feature in the doc? Looking for “separator” doesn’t bring the topic. I have been unable to get this information.

I’m sure the are other terminator. I would have like that ‘’’ be such thing but it’s not. Alas, because I need to code something like this below, in fact:

<$let makeBtn='''<$button actions="""<$macrocall $name=showPart id="$partpartnum$" origin:"$(host)$"/>""">see</$button>'''>

Is there a way? Is that something for a special vocabulary (would be intimidating)?

Note that single quote is a not a correct answer as my title (which is $(host)$ in my code) may very well include them (like in “the fisher’s fishes”).

These symbols are referred to as “quotes” within TW, but I note that the best search term is currently actually the verb form “quoting”.

Anyhow, the docs are here:

https://tiddlywiki.com/#HTML%20in%20WikiText

The material there is really foundational to using TiddlyWiki effectively.

1 Like

thak you @jeremyruston .

Well! So there is not any other ways of quoting yet. So I have to usi two variables to achive my goal and here is the resulting code.

<$let
   actions="""<$macrocall $name=showPart id="$partpartnum$" origin="$(host)$"/>"""
   makeBtn="<$button actions=<<actions>>>see</$button>"
>
 <<makeBtn>>
</$let>

Would it be possible to have ‘’’ as another quoting possibility in a future version?

With careful nesting of all three forms of quoting (single-quotes: ', double-quotes: ", and tripled double-quotes: """), you can achieve the results you want with only one variable, like this:

<$let makeBtn="""<$button actions='<$macrocall $name=showPart id="$partpartnum$" origin:"$(host)$"/>'>see</$button>""">

Note the use of tripled double-quotes around the entire let assignment value, single-quotes around the actions parameter value, and regular double-quotes around the inner $macrocall parameter values.

There is also a handy trick that lets you use that all three kinds of quotes when creating a variable by using the \define pragma:

\define variablename() This value contains """tripled quotes""", and "double quotes" and 'single quotes'

and, you can do this within a macro definition to create local, private variables:

\define myMacro(someparam)
\define variablename() argle "bargle" """$someparam$""" 'mumble' frotz... gronk snork!
... rest of macro goes here ...
\end

This creates a macro named myMacro that takes one parameter (someparam), and then defines a local variable named variablename that is “in scope” until the end of the containing myMacro macro.

Note that the variablename definition must be a “one-liner”; i.e., you can’t use multple lines followed by a \end, as this would prematurely terminate the containing myMacro definition.

Also note that the \define variablename() can’t declare any parameters of its own, since all parameter references within the variablename definition (e.g., $something$) will be processed when the containing myMacro macro is invoked. However, you can use parameters from the containing myMacro macro within the variablename definition, as those values are processed and replaced with the values passed in to myMacro.

As an example: suppose you have a macro, e.g., doFilter, that takes a filter definition as a parameter. Normally, you might write something like this:

\define doFilter(filt)
...
<$list filter="$filt$">...</$list>
...
\end

The problem is that the filter might contain some double-quotes, in which case you might think to use tripled double-quotes around the $list filter parameter, like this:

\define doFilter(filt)
...
<$list filter="""$filt$""">...</$list>
...
\end

This improves things a bit, but there’s still a problem if the value of filt also can contain some tripled double-quotes. In this case, you can use the “local define” method described above as a work-around:

\define doFilter(filt)
\define filt() $filt$
...
<$list filter=<<filt>>>...</$list>
...
\end

Note that this can also be done using the <__param__> “macro param-as-variable” syntax, like this:

\define doFilter(filt)
...
<$list filter=<__filt__>...</$list>
...
\end

So, you can see that, while it’s a bit tricky and subtle, “there are many ways to skin a cat” (the wierdest method is to poke a small hole in the end of their tail and then suck out the innards with a vacuum pump! :grimacing:)

Conclusion: Jeremy is brilliant!

-e

1 Like

image

Nested define pragmas? I have only myself to blame for that construct being completely new to me. Thank you!

Great. I got the pump :sunglasses:
YOU hold the cat :scream:
:laughing:

1 Like

I think you make your life much harder as it should be. Can you show a bit more of the code?

Using text substitution like $partpartnum$ and $(host)$ … isn’t best practice anymore. …

But without the rest of the code we can’t really suggest improvements here, other than probably make your code more complex as it already is.

I think your variables can be converted to “macro” definitions, which internally are variables.
So your code could look similar to

\define myActions() <$macrocall $name="showPart" id=<<getID>> origin=<<host>>/>
\define myButton() <$button actions=<<myActions>>>see</$button>

<<myButton>>

Which would let your quotation problems go away and imo is much easier to read and debug. …

Important: Your code shown here, probably can’t be directly translated to my suggested form. We would need to see more from your code. Especially where the text substitutions $partpartnum$ and $(host)$ come from.

Many thanks to all of you! This is a real trove of know-how! And yes that awesome!

As for concatenation, I know it’s a por practice. I wish we could have something like named parameters in SQL dialect, where this is the motor that takes care of all the security issues.

How could it look like in TW?

1 Like

There is a new proposal at GitHub on the way, that may save this problem in the future. … Add support for string literal attributes with textual substitution · Issue #6663 · Jermolene/TiddlyWiki5 · GitHub

1 Like