Deep-Symmetry/bytefield-svg

Declare the namespaces in the <svg>

ggrossetie opened this issue ยท 8 comments

Is your feature request related to a problem? Please describe.
If you embed the SVG produced by bytefield-svg in a HTML page and serve that page as text/html then xmlns attributes are not required.
But, if the page is served as image/svg+xml or any other MIME type that causes the user agent to use an XML parser then the xmlns attributes are required. Otherwise the browser won't recognize the content and display XML (instead of an image).
For instance: https://a.kroki.io/bytefield/svg/test

It's recommended to declared the namespaces you use in your XML files. If you don't, user agents such as Firefox won't recognize your content and will simply show the XML markup or inform the user that there's an error in the XML. It's a good idea to use a template that includes all the commonly used namespace declarations when creating new SVG files. If you don't already have one, make one up starting with the following code

https://developer.mozilla.org/en-US/docs/Web/SVG/Namespaces_Crash_Course#Conclusion

Describe the solution you'd like
Add the following namespaces:

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
</svg>

Describe alternatives you've considered
I guess not doing it? ๐Ÿค” ๐Ÿ˜†

I used to include these, and removed them because they caused validation errors the way that @Swiftb0y was serving pages. I may have parameterized that though, let me take a look.

How are you calling it? This is controlled by the embedded argument as described on the project homepage: https://github.com/Deep-Symmetry/bytefield-svg#invoking-from-javascript

Yes, it appears that kroki is specifically requesting that bytefield-svg omit these headers. If you stop doing that, they will be present: https://github.com/yuzutech/kroki/blob/8cd767e2c4f213d6d22d7ae12b2c0c278348da12/bytefield/index.js#L12

For a chuckle see also #13 ๐Ÿ˜†

Ooops, I forgot about that sorry ๐Ÿ˜“

No worries! I wrote the silly thing, and didnโ€™t remember how it worked until I went back and looked! Hopefully you will have a straightforward way of deciding when you want to generate embedded svg elements or standalone SVG files?

Can we close this issue?

Hopefully you will have a straightforward way of deciding when you want to generate embedded svg elements or standalone SVG files?

Not really but I will opt for the "standalone" mode. In my opinion the header <?xml version="1.0" encoding="UTF-8" standalone="no"?> should be removed because, as far as I know, it does not bring any value (but I might be wrong).
Having said that, other popular diagrams librairies (for instance, PlantUML) are using it so I can live with that.

Can we close this issue?

Yes, sorry about the noise ๐Ÿ”‡

Unfortunately I get that XML header from the library I use when I tell it to wrap an SVG file, so we would need to open the issue upstream to remove that.