Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiline attributes fail #74

Open
DavidMikeSimon opened this issue Feb 26, 2013 · 13 comments
Open

Multiline attributes fail #74

DavidMikeSimon opened this issue Feb 26, 2013 · 13 comments

Comments

@DavidMikeSimon
Copy link

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
Copy link

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
Copy link

@Sinetheta - super-hoping you revisit this

+1 re: defect

@StoneCypher
Copy link

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

@BenMorganIO
Copy link

@Sinetheta Merci!

@gottfrois
Copy link

Also having the same issue with multi lines

@dzwicker
Copy link

dzwicker commented Nov 2, 2015

+1

@moeabdol
Copy link

I love HAML, but this is killing me.

@roguenet
Copy link

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
Copy link

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
Copy link

@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
Copy link

AnalyzePlatypus commented Jun 14, 2017

@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?

      // 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.

@mebibou
Copy link

mebibou commented Feb 9, 2018

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

@mebibou
Copy link

mebibou commented Feb 9, 2018

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants