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

Warnings when parsing/inlining @rules in css #28

Closed
sn3p opened this issue Nov 19, 2018 · 7 comments
Closed

Warnings when parsing/inlining @rules in css #28

sn3p opened this issue Nov 19, 2018 · 7 comments

Comments

@sn3p
Copy link

sn3p commented Nov 19, 2018

I get these warnings in the console:

14:51:44.763 [warn] Unknown token '@'. Ignoring.
14:51:44.763 [warn] Unknown token '('. Ignoring.
14:51:44.763 [warn] Unknown token ':'. Ignoring.
14:51:44.763 [warn] Unknown token '}'. Ignoring.
14:51:44.804 [warn] Unknown token '@'. Ignoring.
14:51:44.804 [warn] Unknown token '('. Ignoring.
14:51:44.804 [warn] Unknown token ':'. Ignoring.
14:51:44.804 [warn] Unknown token '}'. Ignoring.
14:51:44.831 [warn] Unknown token '@'. Ignoring.
14:51:44.831 [warn] Unknown token '('. Ignoring.
14:51:44.831 [warn] Unknown token ':'. Ignoring.
14:51:44.831 [warn] Unknown token '}'. Ignoring.
14:51:44.845 [warn] Unknown token '@'. Ignoring.
14:51:44.845 [warn] Unknown token '('. Ignoring.
14:51:44.845 [warn] Unknown token ':'. Ignoring.
14:51:44.845 [warn] Unknown token '}'. Ignoring.

When I'm inlining the CSS below:

<style type="text/css">

body {
  width: 100%;
}

@media screen and (max-width: 600px) {
  body {
    width: auto;
  }
}

</style>

When I remove the @media query the warnings are gone.
Doesn't seem to be harmful though, styling seems to be inlined just fine.

@sn3p
Copy link
Author

sn3p commented Nov 19, 2018

Related issue in premailer for Ruby: premailer/premailer#9

@danschultzer
Copy link
Owner

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 😄

@sn3p
Copy link
Author

sn3p commented Nov 20, 2018

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.

@danschultzer
Copy link
Owner

danschultzer commented Nov 25, 2018

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.

@danschultzer
Copy link
Owner

I just added #29 to strip media queries with RegEx. If it works, I'll just push that out for now.

@sn3p
Copy link
Author

sn3p commented Nov 25, 2018

I just added #29 to strip media queries with RegEx. If it works, I'll just push that out for now.

Awesome, looks good!

@danschultzer
Copy link
Owner

v0.3.3 released, thanks!

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

No branches or pull requests

2 participants