markup.ml icon indicating copy to clipboard operation
markup.ml copied to clipboard

Adjust SVG attributes irrespective of their namespace

Open maurobringolf opened this issue 3 years ago • 0 comments

Hi!

I am using tyxml and ran into the same issue as https://github.com/ocsigen/tyxml/issues/307, but with the attribute viewBox instead. It only occurs with the ppx so I looked into the html_parser as suggested by @mooreryan in the issue (thanks!).

As far as I can tell, this is what happens:

  1. Html parser sees <svg> tag and parses it in the SVG namespace here.
  2. This is supposed to trigger the case corrections for attributes in here.
  3. The correction function itself only corrects attributes that have the SVG namespace prefix here.

I don't know enough about namespaces and the use cases of this library, but from my POV there are two fixes:

  1. Add the SVG namespace to all attributes behind the scenes, similar to how the SVG namespace is added to the svg element implicitly.
  2. Ignore the namespace in adjust_svg_attributes because the decision to adjust attribute names is already made by the caller.

This PR adds a test with my own use case and passes it by choosing option 2. I also built and tested the tyxml repository against this PR which works fine.

maurobringolf avatar Jul 07 '22 06:07 maurobringolf