Allow spaces in inline elements with MarkoJS concise markup

90 Views Asked by At

We are using MarkoJS in our new project. I love concise scrypts but in MarkoJS it seems they trim all possible spaces.

The example is:

h1
-- hello
span
    -- Diego!

Outputs:

<h1>Hello<span>Diego!</span></h1>

This output is very similar to HAML's trailing trims command "<". Even after reading the docs, I cannot find a way to leave any inline element defined with concise lang to not trim the trailing space like this:

Outputs:

<h1>Hello <span>Diego!</span> </h1>
1

There are 1 best solutions below

0
On

Where whitespace is important I would suggest using the non-concise syntax since Marko allows you to mix and match the HTML syntax and the concise syntax. For example:

div -- This is concise
<h1>Hello <span>Diego!</span> </h1>
div -- Back to concise

This will produce the following output:

<div>This is concise</div>
<h1>Hello <span>Diego!</span> </h1>
<div>Back to concise</div>

Here's another alternative:

div -- This is concise
h1 -- Hello <span>Diego!</span>
div -- Back to concise

However, that produces a slightly different output that may or may not be what you are looking for:

<div>This is concise</div>
<h1>Hello <span>Diego!</span></h1>
<div>Back to concise</div>

FWIW, it's usually not a good idea to leave trailing whitespace in your source files since the intentions will not be obvious to someone who is just looking at the text (some editors such as Atom will strip out trailing whitespace on save by default).

Hope that works for you.