Open DavidMikeSimon opened 11 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.
@Sinetheta - super-hoping you revisit this
+1 re: defect
A similar, unrelated defect: the multiline pipe setup is also not honored according to the standard
@Sinetheta Merci!
Also having the same issue with multi lines
+1
I love HAML, but this is killing me.
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
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?!
@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 😞
@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?
readme
should clearly state that multiline items will not work // If we reach the end of the line, then there is a problem
if (i > l) {
throw "Malformed attribute block";
}
Maybe a more specific error, like: "Multiline tags unsupported" should be thrown instead. Then this issue can be closed! I've created a PR that makes these changes.
I guess best is to convert all haml files back to good old html! great...
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!
For example, this gives a "malformed attribute block" error:
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.