Closed sn3p closed 5 years ago
Related issue in premailer for Ruby: https://github.com/premailer/premailer/issues/9
Yeah, it's because the regex for the CSSParser doesn't parse @media
query correctly. The selector gets parsed into "@media screen and (max-width: 600px)"
which the HTML parser can't understand.
I'll see if I can fix this by stripping media queries from parsing. In the end though, regex is wrong and I really should build a proper tokenizer for it :smile:
Maybe it's not a big deal, if it's just warnings and they rules are just skipped. But it would be nice if it's possible to suppress these warnings, as they are polluting the console and test results.
I was fiddling with regex to strip all at-rules before parsing, but not fan of regex in this case either.
I've been looking into building a CSS lexer and parser, and checked how Jason decodes JSON.
This ruby library is interesting too: https://github.com/rgrove/crass/blob/master/lib/crass/tokenizer.rb
And there's also this erlang project: https://github.com/acammack-r7/erlang-css
The way Jason does it is probably the better option, but it'll require time to get working. Not sure if I'll have the time available to fix this anytime soon. Any help/suggestions would be welcome.
I wouldn't suppress the warnings just in case there may be some unrelated errors that actually needs fixing. The warnings comes from Floki.
I just added #29 to strip media queries with RegEx. If it works, I'll just push that out for now.
I just added #29 to strip media queries with RegEx. If it works, I'll just push that out for now.
Awesome, looks good!
v0.3.3
released, thanks!
I get these warnings in the console:
When I'm inlining the CSS below:
When I remove the
@media
query the warnings are gone. Doesn't seem to be harmful though, styling seems to be inlined just fine.