pugjs / pug

Pug – robust, elegant, feature rich template engine for Node.js
https://pugjs.org
21.7k stars 1.95k forks source link

Spaces are allowed inside string interpolation, but not inside tag interpolation -- which is inconsistent. #2280

Open audreytoskin opened 8 years ago

audreytoskin commented 8 years ago

I basically follow the Idiomatic.js styleguide for JavaScript, which partly means I'm used to putting whitespace inside brackets, around the contained terms. So, in Jade, I was tempted to write string interpolation like this:

- var foo = "bar";
p #{ foo }

Which seems to work the way it should, with or without the spaces. However, tag interpolation does not seem to allow spaces. The following line

p #[ em blah blah ]

...should produce <p><em>blah blah</em></p> -- but instead it produces <p>em blah blah </p>

Not a major bug, but this seems a little inconsistent to me.

ForbesLindesay commented 8 years ago

I'm not sure this is really that inconsistent. It works for JavaScript interpolation because JavaScript is mostly whitespace-insensitive. It doesn't work for pug because pug is mostly whitespace insensitive. Having said that, we could strip leading whitepsace, which may well be a better UX so I'm not massively against it.