danschultzer / premailex

Preflight for your HTML emails - inline styling and plain text.
MIT License
172 stars 20 forks source link

Add stripping of @charset lines #83

Closed backspace closed 11 months ago

backspace commented 11 months ago

My asset pipeline changed a bit and the generated CSS was updated to start with this:

@charset "UTF-8";

This caused Premailex to crash when inlining styles, like you can see here:

     ** (FunctionClauseError) no function clause matching in Floki.Selector.Parser.do_parse/2

I was able to work around it by adding a Webpack plugin to strip the @charset line from the CSS, but I figured this might happen to others so here’s a draft fix.

It seems hackish, though maybe unavoidable considering #30? I’m also unsure why @keyframes and the like wouldn’t cause similar problems.

danschultzer commented 11 months ago

Yeah, other at-rules will fail as well. I'm gonna merge this, and release fix, but I think I need to build a proper CSS parser instead. Though it can be forced to work in most cases, the regex is hacky.