Skip to content
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

Refactor SVG handling #31

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Refactor SVG handling #31

wants to merge 1 commit into from

Conversation

sairus2k
Copy link

@sairus2k sairus2k commented Feb 4, 2025

Fixes #7

Description

  • Replaced node-html-parser with @xmldom/xmldom for improved SVG parsing and manipulation. Actually, we don't need an HTML parser for SVG parsing - an XML parser is sufficient. The node-html-parser package includes unnecessary CSS-related features, which adds extra dependencies to the utility. Additionally, node-html-parser has a quirk where it adds closing tags instead of using self-closing, resulting in larger SVG sprite file sizes.

  • Improved SVG spritesheet generation by switching from template strings to DOM operations, resulting in more reliable and maintainable code.

  • Fixed configuration in remix-vite-cjs to resolve startup issues.

  • This pull request partially addresses issue Svg minification #7, as the unformatted SVG file will now contain only three lines (first line for XML declaration and last line empty). In my opinion, features like optimizing paths and inlining styles are out of scope for this library, and SVGO already handles these tasks well. Therefore, I suggest closing issue Svg minification #7.

  • Added more meaningful examples for file generation.

Type of change

Please mark relevant options with an x in the brackets.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Algorithm update - updates algorithm documentation/questions/answers etc.
  • Other (please describe):

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also
list any relevant details for your test configuration

  • Integration tests
  • Unit tests
  • Manual tests
  • No tests required

Reviewer checklist

Mark everything that needs to be checked before merging the PR.

  • Check if the UI is working as expected and is satisfactory
  • Check if the code is well documented
  • Check if the behavior is what is expected
  • Check if the code is well tested
  • Check if the code is readable and well formatted
  • Additional checks (document below if any)

Screenshots (if appropriate):

Questions (if appropriate):

Replaced `node-html-parser` with `@xmldom/xmldom` for improved SVG parsing and manipulation. Enhanced SVG spritesheet generation logic by using DOM operations for better maintainability.
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.

Svg minification
1 participant