Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix hash parsing with Haml 6
Remove line breaks before parsing so that Haml::AttributeParser
correctly recognizes a hash.
  • Loading branch information
ledermann committed Dec 11, 2022
commit 07127a99fb32d4f687975403d9c660094367e951
2 changes: 1 addition & 1 deletion lib/syntax_tree/haml/format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ def parse_attributes(source)
program = Ripper.sexp(source)
type = program && program[1][0][0]

if type == :hash && (parsed = ::Haml::AttributeParser.parse(source))
if type == :hash && (parsed = ::Haml::AttributeParser.parse(source.tr("\n", ' ')))
parsed.to_h { |key, value| [key, parse_attributes(value)] }
elsif type == :string_literal
SyntaxTree.parse(source).statements.body[0]
Expand Down
18 changes: 18 additions & 0 deletions test/tag_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,22 @@ def test_interpolation_in_strings
def test_interpolation_in_value
assert_format("%p <small>hello</small>\"\#{1 + 2} little pigs\"")
end

def test_multiline_attributes
assert_format(<<~HAML)
%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
HAML
end
end