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

Multiline attributes fail #74

Open DavidMikeSimon opened 11 years ago

DavidMikeSimon commented 11 years ago

For example, this gives a "malformed attribute block" error:

%img(src="images/foo.png"
     title="Some Image")

However, it works fine in Ruby Haml.

This also needs to be supported for curly-braced attribute blocks; Ruby Haml supports those being multiline as well, though it strictly enforces that each line but the last must end with a comma.

Sinetheta commented 9 years ago

In case someone else ends up here, you can always do the most horrible thing and use a proper implementation of HAML like I did to monkey-patch karma-haml-preprocessor.

I'll be happy to revisit the problem in the future, this was my "need it to work now" fix.

StoneCypher commented 9 years ago

@Sinetheta - super-hoping you revisit this

+1 re: defect

StoneCypher commented 9 years ago

A similar, unrelated defect: the multiline pipe setup is also not honored according to the standard

BenMorganIO commented 9 years ago

@Sinetheta Merci!

gottfrois commented 9 years ago

Also having the same issue with multi lines

dzwicker commented 8 years ago

+1

moeabdol commented 8 years ago

I love HAML, but this is killing me.

roguenet commented 8 years ago

In case someone else comes through here having this trouble with the Karma preprocessor, I wrote another preprocessor that will concatenate your multi-line attributes so that at least within the Karma environment, you can continue to use the much much faster haml-js instead of the hack above to spin up a haml executable for every template (my project has hundreds; that approach was very slow).

https://www.npmjs.com/package/karma-haml-attribute-concatenation-preprocessor

AnalyzePlatypus commented 7 years ago

I'm having the same issue with multiline attributes migrating a HAML webapp out of Rails and unto Gulp. This is intolerable. Has this issue seriously been open for the past 4 years?!

Sinetheta commented 7 years ago

@AnalyzePlatypus I came back to take a look, but on inspection I'd call this unfixable. haml-js is parsing documents using regexes. The core of tag matching is done by https://github.com/creationix/haml-js/blob/master/lib/haml.js#L184 which assumes that each tag exists on a single line.

Although it might be possible to match based on tag delimeters ., #, or % I'm not willing to dive into a library that translates without a parser myself. Sorry, I'd suggest not using haml with js projects 😞

AnalyzePlatypus commented 7 years ago

@Sinetheta: Agreed. I looked over the matcher, and this issue does not seem fixable without revamping most of the parser from scratch. How about making multiline attributes officially unsupported?

mebibou commented 6 years ago

I guess best is to convert all haml files back to good old html! great...

mebibou commented 6 years ago

Ah wait, for those like me wanting to use webpack and having this error, you can use ruby-haml-loader which uses the actual haml gem, so you won't have any errors at all if it works already in your Ruby app!