Skip to content

Commit

Permalink
Merge pull request #41 from x4d3/main
Browse files Browse the repository at this point in the history
Format unquotted attributes
  • Loading branch information
elia authored Jan 10, 2024
2 parents 183125e + 871d15d commit 0dfaace
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/erb/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ def format_attributes(tag_name, attrs, tag_closing)
attrs.scan(ATTR).flatten.each do |attr|
attr.strip!
name, value = attr.split('=', 2)
if UNQUOTED_ATTR =~ attr
attr_html << indented("#{name}=\"#{value}\"")
next
end

if value.nil?
attr_html << indented("#{name}")
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/attributes.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<img src="image.jpg" alt="Responsive Image"
srcset="image-480w.jpg 480w,
image-800w.jpg 800w,
image-1200w.jpg 1200w"
sizes="(max-width: 600px) 480px,
(max-width: 1000px) 800px,
1200px"
data-autocomplete-min-length-value=2>
7 changes: 7 additions & 0 deletions test/fixtures/attributes.html.expected.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<img
src="image.jpg"
alt="Responsive Image"
srcset="image-480w.jpg 480w, image-800w.jpg 800w, image-1200w.jpg 1200w"
sizes="(max-width: 600px) 480px, (max-width: 1000px) 800px, 1200px"
data-autocomplete-min-length-value="2"
>

0 comments on commit 0dfaace

Please sign in to comment.