Wikify/let/set/vars adding spaces

I have a two templates:

<$wikify name="stuff" text="<<currentTiddler>>" mode="inline" output="html" >
<<stuff>>
</$wikify>something

and

<$wikify name="stuff" text="<<currentTiddler>>" mode="inline" output="html" >
<<stuff>></$wikify>something

The first adds space between the “stuff” and the “something”. The second does not. $let, $vars and $set seems to do the same trailing CR → space conversion. Is that expected purposeful behavior?

/Mike

This is not a TiddlyWiki issue. It is the normal behavior when rendering content for any webpage.

The basic rule of thumb is that – absent specific styling (such as <pre>...</pre>, or CSS <span style="white-space:pre;">...</span> or use of <br/> or <p/>) – all whitespace sequences (including newlines) are automatically reduced to single spaces.

Consider, if you have a regular web page (HTML file) containing:

one
two

three
four

It would produce output like this:

one two three four

(i.e, the newlines are converted to spaces and the double newlines becoming a single space)

The output you reported is caused by the newline that follows <<stuff>>, and not because of the enclosing $wikify (or $let, $set, or $vars). You would also get the same result if the newline occured outside of the enclosing $wikify, like this:

<$wikify name="stuff" text="<<currentTiddler>>" mode="inline" output="html" >
<<stuff>></$wikify>
something

Note also that there is a newline within the $wikify that immediately precedes the <<stuff>> content. This will also be rendered by the browser as a space if there was any content before the $wikify:

before<$wikify name="stuff" text="<<currentTiddler>>" mode="inline" output="html" >
<<stuff>></$wikify>after

produces:

before TiddlerNameafter

The only way to completely avoid these “added” spaces, is to not have ANY extra whitespace (includine newlines), like this:

before<$wikify name="stuff" text="<<currentTiddler>>" mode="inline" output="html" ><<stuff>></$wikify>after

which results in:

beforeTiddlerNameafter

-e

2 Likes

Thank you, @EricShulman

An excellent and thorough explanation as usual that explains a mystery/OCD annoyance that I have had for years about where those trailing spaces come from in things I’ve copied and pasted from html-formatted emails and websites.