rgrove / crass

A Ruby CSS parser that's fully compliant with the CSS Syntax Level 3 specification.
MIT License
138 stars 14 forks source link

Extract style_rule inside a media query #17

Closed stoivo closed 2 months ago

stoivo commented 2 months ago

I created one issue where I asked why I don't get rules, https://github.com/rgrove/crass/issues/15#issue-2297848283. I did a bit more research on my own and think there is a bug here. I was reading the documentation on Consume an at-rule, and then we consume { we should "Consume a block from input, and assign the result to rule’s child rules" which meam we should extract rules

stoivo commented 2 months ago

I created a small tool for me to work around this for my need but I think media queries can have declaration directly inside like

  body {
    background-color: black;
    color: white;
    @media screen and (prefers-color-scheme: light) {
      background-color: white;
      color: black;
    }
  }

  body {
    background-color: black;
    color: white;
  }
  @media screen and (prefers-color-scheme: light) {
    body {
      background-color: white;
      color: black;
    }
  }

These two blocks does the same. Maybe they are a new standard to might still be buggy

stoivo commented 2 months ago

in (2013 documentation -> 5.1 Parser Railroad Diagrams)[https://www.w3.org/TR/2013/WD-css-syntax-3-20130919/#parser-diagrams] the spec for At-rule only refers to a block, and a block only has Component value. Also Qualified rule also only have a block even those er parse it with declarations.

in 2021 edition the block is the same, but in 2024 draft 22.april edition the block is more advanced

rgrove commented 2 months ago

I don't think there's a bug here because Crass currently implements the 14 November 2014 editor's draft of CSS Syntax Level 3, and I believe this is the behavior it defines. However, you're correct the the latest drafts have introduced significant changes.

Issue #14 already tracks the desire to add support for nesting (which was the reason for most of the spec changes), so I think that's probably the best place for any further discussion. I did some exploratory work on this a while back — enough to determine that the necessary changes won't be trivial — but I haven't had time to go further.