Tidying Whitespace
Quick Overview Video
Where to put your line breaks
Take this example of a snippet where we have three sections the user can optionally include when they use the snippet.
{formtoggle: name=Option 1}Optional section 1...{endformtoggle}
{formtoggle: name=Option 2}Optional section 2...{endformtoggle}
{formtoggle: name=Option 3}Optional section 3...{endformtoggle}
Concluding text...
This snippet will insert perfectly if you choose all three sections, but if you don't choose them all, you'll see extra whitespace when inserting. For example, if we only checked the third we would get:
Optional section 3...
Concluding text...
This is because when you uncheck a {formtoggle} command, Text Blaze removes everything inside the toggle, but since we have the line breaks outside the toggle they are kept.
Fortunately, the fix is very simple: just move the line breaks inside of the toggles. Then they will be removed when you uncheck the toggles. Doing this, you should end up with something like this:
Optional section 1...{endformtoggle}{formtoggle: name=Option 2}
Optional section 2...{endformtoggle}{formtoggle: name=Option 3}
Optional section 3...{endformtoggle}
Concluding text...
That's a little harder to read in the snippet source, but it will give you exactly what you want when you insert it no matter which sections you check.
This tip also applies to the {if} and {repeat} commands.
The trim
setting
Every command has an optional trim
setting that allows you to remove whitespace before or after the command.
The trim
setting can take one of four values: "yes" to trim on both sides, "left" to trim on the left side only, "right" to trim on the right side only, and "no" to not trim at all (the default if the trim
setting is omitted). Let's see it at work with the {time} command.
[ {time: LL; trim=yes} ]
[ {time: LL; trim=left} ]
[ {time: LL; trim=right} ]
The trim
setting can also be used to improve our example above by letting us add some additional whitespace to make the snippet source more readable without changing the final insertion:
{formtoggle: name=Option 1; trim=left}
Optional section 1...{endformtoggle}
{formtoggle: name=Option 2; trim=left}
Optional section 2...{endformtoggle}
{formtoggle: name=Option 3; trim=left}
Optional section 3...{endformtoggle}
Concluding text...
Trimming whitespace in formulas
Lastly, for our advanced formula users, the Text Blaze formula language has a trim
function that will remove whitespace from strings in formulas.
For example: