Swaagie / minimize

Minimize HTML
MIT License
162 stars 18 forks source link

Inline SVG self-closing tags #24

Open pixeltherapy opened 10 years ago

pixeltherapy commented 10 years ago

In the same vein as #23 but with a common use scope, certain inline SVG elements are breaking due to changes in self-closing tags. In this case 'quotes:true' is optioned to prevent breaking of fill declarations, e.g. fill="url(#foo)".

Source:

<linearGradient id="foo">
  <stop offset="0" stop-color="#fff" />
  <stop offset="1" stop-color="#000" />
</linearGradient>

Output :

<lineargradient id="foo">
  <stop offset="0" stop-color="#FFF">
    <stop offset="1" stop-color="#000">
    </stop>
  </stop>
</lineargradient>

While this effects many SVG elements it does not seem to break primitives such as <rect /> and <circle />, no doubt these elements are a little more robust.

Swaagie commented 10 years ago

Yes and no (concerning scope), this is also a known issue with htmlparser2. It has no full support for all SVG elements (yet). But since SVG is not user-defined it should be doable to create a parser that correctly parses all SVG elements. As you can see https://github.com/fb55/htmlparser2/issues/79, I've ran into the issue myself as well. Like #23 this issue is more suited for htmlparser2/domparser.

However, i'll keep this one open. I haven't got the time myself to implement/extend the parser, but perhaps others can chip in?

pixeltherapy commented 10 years ago

I agree, it is very doable and hardly earth-shattering as issues go.

Thanks for the link to htmlparser2, I'll have a look and see if I can contribute, because, y'know I'm all about that SVG. Will update here with any significant progress/updates.

Swaagie commented 10 years ago

Sounds good, will keep an eye out and perhaps chip in some time as well