svgdotjs / svgdom

Straightforward DOM implementation to make SVG.js run headless on Node.js
MIT License
275 stars 54 forks source link

Namespaced attributes are not exported correctly #100

Open wout opened 1 year ago

wout commented 1 year ago

I'm using svgdom for a project, and it's doing an awesome job. So far, it has helped us generate over 4000 SVG files which are then exported to PNG using Inkscape.

We had one issue though. Namespaced (xlink) attributes are rendered without the namespace. I've now fixed this in Crystal on the server side:

  private def fix_svg_xlink_attributes(svg)
    svg.gsub(/ href="#/, %( xlink:href="#))
  end

But it's not an ideal situation.

I'm just calling outerHTML on the generated SVG element. Maybe I'm missing something?

Fuzzyma commented 1 year ago

Mh, usually attributes should contain the name space if there were created with such. Is it only happen with xlink or are other namespaces affected as well?

The namespace part is not the easiest part of the Dom spec to understand tbh so it's very well possible that there is a bug in the implementation :D

wout commented 1 year ago

That's the only namespace we use, so I'm not sure if it also affects others. We're not using SVG.js btw, just a micro SVG lib. It's using setAttributeNS on the elements in question. Calling outerHTML in the browser and saving that to a file does work. So something's not right there.

I can give you access to the repo if you want. It's a simple internal Node app with three endpoints each returning an SVG.