Tidying Whitespace
Quick Overview Video
If you're using advanced commands inside of your snippets you may be formatting your snippet using line breaks or spaces to improve readability for your team or yourself.
Any whitespace that you're using to format the snippet itself will also appear in the snippet's final output.
The first section will show you a command setting to quickly remove whitespace.
Also, if you're curious about why this happens, we'll cover it in more detail in the Where to put your line breaks in Text Blaze section.
The trim
setting
Every Text Blaze command has an optional trim
setting that allows you to remove whitespace around the command.
The trim
setting can take one of four values:
- "yes" - trim whitespace on all sides of the command.
- "no" - Do not trim any whitespace at all. ("no" is the default value if the
trim
setting is omitted from a command.)
Before getting to the final two values you can use, let's see a quick example:
[ {time: LL; trim=yes} ]
Notice how if you add spaces to the top and bottom of the second {time} command the final output will still be clean and without whitespace.
But, what if you want to only remove whitespace on a single side of the command? The two final values that you're able to use for the trim
setting are left
and right
. They remove whitespace only on a single side. See the example below.
[ {time: LL; trim=left} {formtext: default=Hello} ]
Notice how the top example will put the form right beside the time. That's because it's removing all the whitespace completely around the command with the yes
value. The bottom example, on the other hand, allows the form to be directly below the time command. Using right
or left
as a value is useful when you want more fine-grained control.
What if you're using the {=} (Formula Command) command and you need to get rid of additional whitespace for some input? Let's dive into how to do that in the next section.
Trimming whitespace in formulas
If you're using the {=} (Formula Command) command, the Text Blaze formula language has a trim
function that will remove whitespace from strings in formulas.
For example:
Here's another, more advanced example. Let's say that you've just retrieved a user's full name from the website that you're on using the Text Blaze {site} command. But, due to the formatting on the website, it comes with a bunch of extra linebreaks and spaces.
Unlike the trim
setting which removes all whitespace (including line breaks), Text Blaze's trim
function only removes whitespace on the left and right sides. If you would like to remove linebreaks, you need to use the replace
function. Here's an example below.
{=replace(name, "\n", "")}
Double click the name variable above and notice how the formatting of the string contains spaces and linebreaks.
Where to put your line breaks in Text Blaze
Generally, Text Blaze will output your snippet as is, including all the whitespace you've added. Let's dive a bit more technical example using multiline commands.
With multiline commands like {if} or {formtoggle} you generally want to have trailing or leading new lines be within the command. This can be counterintuitive as it's generally not how you would write the snippet by default.
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:
Let's look at one last example. With multiline commands like {if} or {formtoggle} you generally want to have trailing or leading new lines be within the command. This can be counterintuitive as it's generally not how you would write the snippet by default. Let's see an example of this below.
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}, {repeat}, and the {note} commands.
A note on the note command
Text Blaze provides you with the {note} command. By default, the contents of a note are shown in the snippet's preview but are not inserted as part of the snippet. Despite this, the note command still takes up the whitespace used in the final snippet output. Let's see an example:
Notice how there's a line break above "Dear Colleague...". It's advised that you use the trim
setting on notes so that whitespace is not included in your final snippet output.