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

Style empty if `text-align` is `start` #151

Closed mganss closed 9 months ago

mganss commented 11 months ago

I have a feeling this is a configuration issue but I can't figure out what I'm missing here:

var html = @"<p style=""text-align: start;"">this is the content of the p tag</p>";
var parser = new HtmlParser(new HtmlParserOptions { IsScripting = false }, 
    BrowsingContext.New(Configuration.Default.WithCss(new CssParserOptions())));
var dom = parser.ParseDocument(html);
var style = dom.Body.FirstElementChild.GetStyle();
var decls = style.Count(); // -> 0
var css = style.ToCss(); // -> ""

This does not occur if the value of text-align is left for example.

FlorianRappl commented 11 months ago

I think its rather that start is not a valid value for text-align. Remember that the spec is living, and especially CSS is moving rapidly.

Back then the text-align (not text-align-last) was equivalent to the horizontal alignment (https://github.com/AngleSharp/AngleSharp.Css/blob/devel/src/AngleSharp.Css/Declarations/TextAlignDeclaration.cs#L11C51-L11C79), i.e., https://github.com/AngleSharp/AngleSharp.Css/blob/devel/src/AngleSharp.Css/Constants/Map.cs#L96.

That being written, surely we can support the new values for text-align.

mganss commented 11 months ago

FWIW this used to work before AngleSharp 0.10:

var html = @"<p style=""text-align: start;"">this is the content of the p tag</p>";
var parser = new HtmlParser(new HtmlParserOptions { IsScripting = false }, 
BrowsingContext.New(Configuration.Default.WithCss(e =>
{
    e.Options = new CssParserOptions
    {
        IsIncludingUnknownDeclarations = true,
        IsIncludingUnknownRules = true,
        IsToleratingInvalidSelectors = true,
    };
})));
var dom = parser.Parse(html);
var style = dom.Body.FirstElementChild.Style;
var decls = style.Count(); // -> 1
var css = style.ToCss(); // "text-align: start"
FlorianRappl commented 9 months ago

Landed in devel.

wghilliard commented 8 months ago

Hey @FlorianRappl , thank you for all of the work to support this library! Would it be possible to back port this change to the 0.X line? I realize it's scheduled for 1.0 but the product I work on is not allowed to use alpha versions of dependencies for compliance reasons. I notice the 1.0 release is has seen a lot of activity lately, but it's not clear to me when it might be available.

FlorianRappl commented 7 months ago

Unfortunately no - if that particular patch is relevant for your company then maybe sponsoring AngleSharp / other relevant libraries would be a great start to contributing back.

wghilliard commented 7 months ago

Do you have an ETA on when version 1.0 might be released?

FlorianRappl commented 7 months ago

I wanted to close it out in February, but there are too many projects consuming my time. I'd say not before mid / end of March.

wghilliard commented 7 months ago

Okay I understand, thank you, I'll check back in then!