bodoni / svg

Composer and parser for SVG
Other
302 stars 44 forks source link

Issue with self closing element when the generated svg is embedded in html #16

Closed ghost closed 3 years ago

ghost commented 5 years ago

When the generated SVG is put into an HTML document and served into a browser, many browsers will autocorrect the markup. They will find tags that are not permitted to use />, and will automatically insert a closing tag.

E.g. becomes when loaded in an HTML page in Google Chrome.

Is it possible to disable the short version and force a verbose output ?

Edit: I'm using the to_string() method of Document to convert into string

IvanUkhov commented 5 years ago

I believe the logic can be seen here. There is no way to configure this at this point.

crabmusket commented 3 years ago

For future reference, here's the correct permalink where the self-closing formatting can be found: https://github.com/bodoni/svg/blob/a391bb2b3bdd0f4e7d001895f731fb255800eabc/src/node/element/mod.rs#L68

IvanUkhov commented 3 years ago

Thank you for the correction. Right, one would have to distinguish two cases there: permitted to close without a closing tag or not, depending on the element. To this end, perhaps Element should be extended with some flags to communicate more about how each element behaves.

IvanUkhov commented 3 years ago

Can anybody please provide a link to the spec that shows that certain tags are not permitted to be self-closing? If the current behavior is in accordance with the specification, nothing has to be changed.

IvanUkhov commented 3 years ago

I leave this one as a reference and close this issue:

https://stackoverflow.com/questions/24299969/closing-svg-tags-explicit-or-self-closing

Please shout if there is a contradicting and more reliable reference.