crass
crass copied to clipboard
Expose start and end token for simple_rule, needed for sourcemaps
I think it would be good to add two more values to style_rule node. block_start amd block_end
css = <<~CSS
body {font-size:small;}
CSS
# body {font-size:small;}
# 01234567891111111111222
# 0123456789012
pp tree = Crass.parse(css, :preserve_comments => false)
[{:node=>:style_rule,
:selector=>
{:node=>:selector,
:value=>"body",
:tokens=>
[{:node=>:ident, :pos=>0, :raw=>"body", :value=>"body"},
{:node=>:whitespace, :pos=>4, :raw=>" "}]},
:children=>
[{:node=>:property,
:name=>"font-size",
:value=>"small",
:children=>
[{:node=>:ident, :pos=>16, :raw=>"small", :value=>"small"}],
:important=>false,
:tokens=>
[{:node=>:ident,
:pos=>6,
:raw=>"font-size",
:value=>"font-size"},
{:node=>:colon, :pos=>15, :raw=>":"},
{:node=>:ident, :pos=>16, :raw=>"small", :value=>"small"}]},
{:node=>:semicolon, :pos=>21, :raw=>";"}]},
{:node=>:whitespace, :pos=>23, :raw=>"\n"}]
One option might be to expose tokens
@stoivo Can you explain about about the use case, to help readers understand why you're asking for this feature?
Yes, I just briefly mention it in the title. Good to expand on that. I am working on refactoring css_parser. One of the features is to see where the rules are defined. Something like source maps for css and javascript.
Does that explain it?