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

merge 'class' attr when both img and svg specify it #9653

Merged
merged 5 commits into from
Apr 15, 2024
Merged

Conversation

cscheid
Copy link
Contributor

@cscheid cscheid commented Apr 12, 2024

Closes #9652.

Comment on lines 7 to 8
<svg id="svg_b627f92299158b36552b" role="img" class="something" width="504.00pt" height="360.00pt" viewBox="0 0 504.00 360.00" class="something please-do-not-delete-me">
</svg>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem quite right; note that there are two class attributes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh that's unfortunate. I completely missed that, thank you.

@cscheid
Copy link
Contributor Author

cscheid commented Apr 12, 2024

Would you prefer I cleanup (squash) these commits or for you to do that yourself?

@@ -258,12 +258,10 @@ combineSvgAttrs svgAttrs imgAttrs =
dropPointZero t = case T.stripSuffix ".0" t of
Nothing -> t
Just t' -> t'
combinedAttrs = concat [
imgAttrs,
combinedAttrs = replaceMaybe mergedClasses $ imgAttrs ++
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using replaceMaybe I'd suggest getting rid of that function and just added "class" to the list at ln. 264 and also use [kv | (k,v) <- imgAttrs | k /= "class"].

But isn't there another possible source of duplicated attributes? For example, suppose imgAttrs contains widdth and so does svgAttrs; won't we get two width attributes?

Copy link
Contributor Author

@cscheid cscheid Apr 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using replaceMaybe I'd suggest getting rid of that function and just added "class" to the list at ln. 264 and also use [kv | (k,v) <- imgAttrs | k /= "class"].

Thanks - my Haskell is (very visibly) rusty, and I forgot about comprehensions.

But isn't there another possible source of duplicated attributes? For example, suppose imgAttrs contains widdth and so does svgAttrs; won't we get two width attributes?

Yes, I believe we will. I had a narrow fix in mind for the class attribute since the other ones don't seem to have a natural way to merge the data. I can make further changes, but I don't know what you would prefer:

  • let imgAttrs attribute win
  • let svgAttrs attribute win
  • issue a warning
  • issue an error

The current behavior (duplicating width attribute) appears to not cause an error on either Google Chrome or Firefox, and the first attribute wins: <svg width="200" width="300"></svg> becomes a DOM element with width="200". With that said, I don't know if this is enough to justify inaction in your view (and I don't know if there's a spec that enforces this).

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.

--embed-resources drops the classes of embedded image when embedding element has classes of their own
2 participants