Triple double quotes not working

Sorry if this has been asked before. This…

<$wikify name="notetext" text="""$note$""" output="html"><<notetext>></$wikify>

does not work when $note$ ends with a double quote. I assume the same would occur if $note$ started with a double quote.

How should this be corrected?

Thank you,

Craig

Because you are using $note$ syntax, I assume your code is contained within a \define somemacro(note)... definition. If so, then you can completely avoid the use of the tripled doublequotes around “”"$note$"""" and instead use <<__note__>> to refer to the parameter value, like this:

<$wikify name="notetext" text=<<__note__>> output="html"><<notetext>></$wikify>

Also, since you are just rendering the resulting notetext, you might be able to completely omit the $wikify widget, and just output $note$ directly, since it will be automatically rendered when the macro output is rendered.

-e

3 Likes

This is not really an answer to your question. But my workaround — throughout my academic wikis, which require quote-marks quite often! — is to make all my actual content use curly-quotes and real apostrophes “” ‘’, so that only my code uses prime and double-prime marks ' " (my snooty typography name for the simpler version of quote marks and apostrophes as the keyboard usually creates them).

Curly marks do look nicer and carry more info! But this commitment does generate a nuisance whenever I’m pulling in content from other sources.

1 Like

@EricShulman Thank you. I will consider both of these solutions. There are numerous places I have used triple quotes.

In this case you are using triple double quotes, I tend to call these “quotes” in contrast to single Quotes. So I may have said triple quotes.

In many ways all you need to know is what may be inside the quotes and use that which is not. If you wanted the following “quoted” "$note$" you can use '"$note$"'

'
"
"""

See here Literal Attribute Values which explains the three methods above. However if the value is delimited by any other means the quote(s) may not be needed at all, eg <<>> the one @EricShulman shared <<__ __>>, {{ }} etc…

My point is if your content/value contains " use ', if it contains ' use ", and if it contains both, in some case you can use """ if you can separate it from ".

This is common in many languages.

Thanks. In many cases the content is unknown, so I need support all cases, which means I cannot use any type is quote. Many languages have a way of escaping characters.

The devil is in the detail of course however you should be able to have your strings referenced in a way that avoids the need to use any type of quote by “leaning” on tiddlywikis own delimiters. Although do your strings contain tripple quotes?

Feel free to share some examples of problematic strings. I am confident tiddlywiki has sufficiant delimiters that we can handle most if not all posible cases.

I have numerous examples. In the example I provided, each tiddler in the system supports a “postnote” field.

When populated a ViewTemplate displays it. The ViewTemplate calls a method:

\define showpostnote(title, note, colour, style, post, link)

In this macro it displays the content (body) of the note from this postnote field. Originally I used:

<$wikify name="notetext" text="""$note$""" output="html"><<notetext>></$wikify>

@EricShulman suggested I use (which I did implement):

<<__note__>>

Whatever is used here it needs to support any characters the user could type in the postnote field. Does the above approach do this, or are there characters that could cause an issue?

I have used triple double quotes throughout. Should these all be changed? Example:

\define ShowStats(filtering)
<$list variable=result filter="""$filtering$"""><<result>></$list>
\end

Here’s a good rule-of-thumb:

If you are passing in a macro parameter that comes from USER input, assume that it can contain ANY combination of characters (including single, double, or tripled-double quotes). This is because users can type in those quote characters, even if they wouldn’t really make any sense for the intended use-case.

In addition to the """$param$""" case, you should also be careful when using filteroperator[$param$] within filter syntax, because a user could enter an errant [ or ] in their input, which would then break the filter syntax.

For \define macros, you can generally avoid both of these situations by using <<__param__>> (or <__param__> in filters). For \procedure “macros”, you can use <<param>> (or <param> in filters) to accomplish the same thing.

…and, for use-cases where you need to construct a text value with added literal text as prefix or suffix, you can even do something like the following to avoid using ANY kind of quotes or square brackets to set a variable:

\define mymacro(someparam)
\define somevariable() before$(someparam)$after
...

and then refer to <<somevariable>> (or <somevariable> in filters) to use the constructed value.

edit: in the above example, the reference to $(someparam)$ should be $someparam$, like this:

\define somevariable() before$someparam$after

enjoy,
-e

4 Likes

@EricShulman Thank you. I have work to do.

100%. I use them in all my content.