Skip to content

Conversation

@johnkenny54
Copy link
Contributor

@johnkenny54 johnkenny54 commented Aug 20, 2024

This PR modifies SVGO to always preserve white space within <foreignObject> elements. In general there is no way to know the semantics of the <foreignObject> content, so all white space within the element is preserved.

The following changes were made:

  • parser.js - keeps track of whether the parser is within a <foreignObject> element, and if so does not trim text or comment nodes.
  • stringifier.js - keeps track of whether the stringifier is within a <foreignObject> element, and if so does not emit prettification indentation or newlines.
  • _collections.js - removed 'pre' from textElems set - this was added by PR fix: dont trim pre elements #1796, but is not necessary since all <foreignObject> content now preserves white space.`.
  • Added a test case to confirm that CDATA and comments are preserved within a <foreignObject>.
  • Modified expected results in several test files. In all cases, the expected result is now to preserve the contents of the <foreignObject> element exactly.

Resolves #1678, resolves #1473.

@rnwst
Copy link

rnwst commented Nov 1, 2024

Thanks for this PR. If all it does is to preserve white space within foreignObject elements, then it does not address #1728. #1728 is about invalid self-closing tags, not preserving whitespace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Non-breaking spaces in <foreignObject> get trimmed Incorrect parsing of html tags within foreignObject tags

2 participants