AngleSharp / AngleSharp.Css

:angel: Library to enable support for cascading stylesheets in AngleSharp.
https://anglesharp.github.io
MIT License
72 stars 34 forks source link

How Parse css style fill rule? #59

Closed StefanoBalzarottiEnnova closed 4 years ago

StefanoBalzarottiEnnova commented 4 years ago

I have this CSS:

var css = @"
    .st0{fill:#AFAA96;stroke:#AFAA96;stroke-miterlimit:10;}
    .st1{fill:none;stroke:#738282;stroke-width:32;stroke-miterlimit:10;}
    .st2{display:none;fill:none;stroke:#738282;stroke-width:32;stroke-miterlimit:10;}
    .st3{display:none;fill:none;stroke:#FAFAFA;stroke-width:32;stroke-miterlimit:10;}"

I try to parse with:

CssParser cssParser = new CssParser();
                    var style = cssParser.ParseStyleSheet(css);
 foreach (ICssStyleRule rule in style.Rules)
 {
    Console.WriteLine(rule.CssText);
 }

The output is:

//.st0 { stroke: rgba(175, 170, 150, 1); stroke-miterlimit: 10 }
//.st1 { stroke: rgba(115, 130, 130, 1); stroke-width: 32; stroke-miterlimit: 10 }
//.st2 { display: none; stroke: rgba(115, 130, 130, 1); stroke-width: 32; stroke-miterlimit: 10 }
//.st3 { display: none; stroke: rgba(250, 250, 250, 1); stroke-width: 32; stroke-miterlimit: 10 }

What happened to fill rule?

FlorianRappl commented 4 years ago

I don't see a declaration for fill - so I guess its discarded.

See https://github.com/AngleSharp/AngleSharp.Css/tree/master/src/AngleSharp.Css/Declarations

By default "unknown" declarations are dropped - you can, however, activate these. Use the CssParserOptions to enable the behavior (see https://github.com/AngleSharp/AngleSharp.Css/blob/master/src/AngleSharp.Css/Parser/CssParserOptions.cs#L14).

We should add the declaration.

FlorianRappl commented 4 years ago

Fix available in devel and the 0.14.3 preview on NuGet.