Skip to content

Fix hash parsing with Haml 6 #61

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

Closed

Conversation

ledermann
Copy link

@ledermann ledermann commented Dec 11, 2022

This PR fixes #35 which describes a bug when formatting a multi-line hash as in this (correctly formatted) example:

%ul.nav.nav-tabs.mb-4
  %li.nav-item
    %button.nav-link.active{
      data: { bs_toggle: "tab", bs_target: "#file" },
      type: "button"
    }
      File
  %li.nav-item
    %button.nav-link{
      data: { bs_toggle: "tab", bs_target: "#video" },
      type: "button"
    }
      Video

With Haml 5, there is no problem. But with Haml 6, the indention of the hash is removed because Haml::AttributeParser seems (?!) not to allow line breaks while parsing. This results in the hash being treated as a PlainPart (no indention) rather than a HashAttributesPart (with indention).

Maybe this is a bug in Haml 6 (I haven't investigated this further), but to fix this here, the line breaks will be removed before parsing.

This PR also adds a test that fails without the change and passes with the change.

Remove line breaks before parsing so that Haml::AttributeParser
correctly recognizes a hash.
ledermann added a commit to templatus/templatus-hotwire that referenced this pull request Dec 11, 2022
@Petercopter
Copy link

@ledermann This works for me, thank you! 👍

@kddnewton
Copy link
Member

This is now fixed in version 4. It strips out our use of the HAML parser entirely and just uses syntax tree now. Thanks for the contribution and report!

@kddnewton kddnewton closed this Mar 7, 2023
ledermann added a commit to templatus/templatus-hotwire that referenced this pull request Mar 24, 2023
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

Successfully merging this pull request may close these issues.

Incorrect Formatting for Multiline Attributes
3 participants