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

CSS shorthand property **text-decoration** is not properly expanded #35

Closed atlastodor closed 5 years ago

atlastodor commented 5 years ago

Bug Report

Prerequisites

For more information, see the CONTRIBUTING guide.

Description

CSS shorthand property text-decoration is not properly expanded.

Steps to Reproduce

  1. Configure AngleSharp WithCss.
  2. Using a new BrowsingContext, parse this HTML:
    <!DOCTYPE html>
    <html>
    <head><title></title></head>
    <body style="text-decoration: underline dotted;"></body>
    </html>
  3. Get the style for the Body element. var styleDeclaration = document.Body.ComputeCurrentStyle();

Expected behavior: As per CSS text-decoration

<'text-decoration-line'> || <'text-decoration-style'> || <'text-decoration-color'>.

"text-decoration-style: dotted"
"text-decoration-line: underline"

Actual behavior:

"text-decoration-style: underline"
"text-decoration-line: dotted"

Environment details: Windows 10, .Net 4.7

Possible Solution

Swap so text-decoration-style is expanded into text-decoration-line and vice-versa.

PS: When you are changing CSS properties behavior, could you please override the ToString() method to return the CssText. This will make working in the debugger much easier.

FlorianRappl commented 5 years ago

Thanks for the report. I'll look into it.

PS: When you are changing CSS properties behavior, could you please override the ToString() method to return the CssText. This will make working in the debugger much easier.

Unfortunately, this was one of the original designs and it has many pitfalls. What I can recommend is either working with some auto variables or something like OzCode.

Just for debugging reasons ToString should not be overridden. Instead, DebuggerDisplayAttribute could be used in such cases (which was already used in AngleSharp in earlier versions; but as explained we discarded that). One of the reasons not to use it in AngleSharp (and AngleSharp.Css) is that this output (W3C serialization) may be confusing at times and does not tell the whole story (e.g., two classes may be have the same serialization).

FlorianRappl commented 5 years ago

Landed in devel.

atlastodor commented 5 years ago

Just for debugging reasons ToString should not be overridden. Instead, DebuggerDisplayAttribute could be used in such cases (which was already used in AngleSharp in earlier versions; but as explained we discarded that). One of the reasons not to use it in AngleSharp (and AngleSharp.Css) is that this output (W3C serialization) may be confusing at times and does not tell the whole story (e.g., two classes may be have the same serialization).

OK. I understand. Normally when I need such a thing, my method will return something like: ToString() => this.GetType().Name + ": " + this.MyName; … so that the object can easily be debugged, but users won't confuse ToString with something returning useful information.

FlorianRappl commented 5 years ago

This sounds like a great strategy @atlastodor. I guess we could do something like this!