Open rnwst opened 1 year ago
Turns out this is a duplicate of #1473. That issue also points out that SVGO treats whitespace inside <foreignObject>
elements incorrectly, something I hadn't noticed initially, but is still an issue in version 3.0.2.
I don't think the self-closing tag is invalid. The content within a <foreignObject>
has to be XML, which means it's XHTML, not HTML, so <span/>
should be equivalent to <span></span>
.
There is still a problem with whitespace being trimmed, and as pointed out in #1678, the safest solution is to preserve all white space within a <foreignObject>
.
Yep, <foreignObject>
is a different world, which SVGO knows nothing about. That's not a bug, since special handling of <foreignObject>
was never implemented (as far as I concerned). PRs are welcome.
Describe the bug When an empty tag is present inside of a
<foreignObject>
element, SVGO converts it to a self-closing tag. This results in tags that are invalid HTML and are misinterpreted by the browser.To Reproduce Steps to reproduce the behavior:
Run
svgo test.svg --pretty --indent=2
, wheretest.svg
:Observe the result, which is:
Note that the empty
<span>
element has been converted to a self-closing tag. This results in invalid HTML, since<span>
is not a void element. The browser actually interprets the self-closing tag as an opening tag, and then automatically closes the tag later on. This is essentially equivalent to:(See here for more information.) When viewing the SVG in a browser, keep in mind that
<foreignObject>
elements will not be rendered unless the SVG is inside of an HTML page. To fix this, add<html>
tags and save the file as an HTML file.Expected behavior Inside
<foreignObject>
elements, empty elements should not be converted to self-closing tags.Version info: