creationix / haml-js

Haml ported to server-side Javascript. This is a traditional server-side templating language. Tested with node-js
MIT License
902 stars 110 forks source link

inconsistent handling of indent #64

Closed acthp closed 12 years ago

acthp commented 12 years ago

Not sure about this, but I didn't expect it. Two space indent is handled differently than one space indent or tab.

a=haml.compile('%table\n\t%tr') '"

" + \n"
" +\n"" + \n""' a=haml.compile('%table\n %tr') '"" + \n"
" +\n"" + \n""' a=haml.compile('%table\n %tr') '"" + \n"" + \n"" + \n"
"'

acthp commented 12 years ago

with better formatting


> a=haml.compile('%table\n\t%tr')
'"<table>" + \n"</table>" +\n"<tr>" + \n"</tr>"'
> a=haml.compile('%table\n %tr')
'"<table>" + \n"</table>" +\n"<tr>" + \n"</tr>"'
> a=haml.compile('%table\n  %tr')
'"<table>" + \n"<tr>" + \n"</tr>" + \n"</table>"'
aaronblohowiak commented 12 years ago

This is the expected behavior. Only two-space indent is valid in creating a new context.

acthp commented 12 years ago

It isn't really haml, then, is it?

> echo $'%table\n\t%tr' | ~/.gem/ruby/1.8/bin/haml
<table>
  <tr></tr>
</table>

> echo $'%table\n %tr' | ~/.gem/ruby/1.8/bin/haml
<table>
  <tr></tr>
</table>

echo $'%table\n  %tr' | ~/.gem/ruby/1.8/bin/haml
<table>
  <tr></tr>
</table>

This should at least be loudly documented, since haml files aren't processed correctly, and it's different from other languages with syntactic white space.

aaronblohowiak commented 12 years ago

if you make tests, add a flag or property to enable this behavior and change the regexp on line 476 (the two spaces before the "(.*)" ), i'll accept a pull request.