-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SVGO creates invalid self-closing tags inside <foreignObject>
elements
#1728
Comments
Turns out this is a duplicate of #1473. That issue also points out that SVGO treats whitespace inside |
I don't think the self-closing tag is invalid. The content within a 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 |
Yep, |
@johnkenny54 This depends on where the SVG is located. If it is loaded as an external resource of type Since SVGO appears to be built on top of an XML parser, I think the easiest fix for this bug might just be to leave |
@rnwst - thanks for this info. I went down some other rabbit holes and didn't look at this embedded in an HTML file. I totally agree that SVGO's first priority should be correctness. Unfortunately, this is not the case. I've been working on a version that prioritizes lossless compression - https://www.npmjs.com/package/svgo-ll - the latest version of svgo-ll handles the situation raised by this issue. As you point out, the only reliable way to deal with this is to preserve everything within the |
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:
svgo test.svg --pretty --indent=2
, wheretest.svg
: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:
The text was updated successfully, but these errors were encountered: