Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing CSS shorthand property containing variable as value #171

Open
5 tasks done
csiga00 opened this issue May 14, 2024 · 5 comments
Open
5 tasks done

Parsing CSS shorthand property containing variable as value #171

csiga00 opened this issue May 14, 2024 · 5 comments
Labels

Comments

@csiga00
Copy link

csiga00 commented May 14, 2024

Prerequisites

  • Can you reproduce the problem in a MWE?
  • Are you running the latest version of AngleSharp.Css?
  • Did you check the FAQs to see if that helps you?
  • Are you reporting to the correct repository? (there are multiple AngleSharp libraries, e.g., AngleSharp.Xml for Xml support)
  • Did you perform a search in the issues?

Description

I'm using version 1.0.0-alpha-99.

I try to replace CSS variables with actual value in a html file (I have a pdf export tool that can't handle css variables in the pre-generated html). I'm playing with AngleSharp(.Css) to parse the html file and see what can I do with it. First of all, I parsed the html content and checked the parsed style objects.
I noticed, that if a variable is used in a shorthand css property, Value is empty in all the longhand properties, even the simple ones (e.g 1px or solid, etc). If I parse a single css property (one of the longhand) with variable, Value is set correctly.

Sorry, if this is not a bug, but by design or if I'm using AngleSharp in the wrong way. I'm really new to it and I might have missed something.

Thanks for help!

Steps to Reproduce

new AngleSharp.Css.Parser.CssParser(new AngleSharp.Css.Parser.CssParserOptions() { IsIncludingUnknownDeclarations = true, IsIncludingUnknownRules = true, IsToleratingInvalidSelectors = true }).ParseDeclaration("border-bottom: 1px solid var(--pale-grey);")

new AngleSharp.Css.Parser.CssParser(new AngleSharp.Css.Parser.CssParserOptions() { IsIncludingUnknownDeclarations = true, IsIncludingUnknownRules = true, IsToleratingInvalidSelectors = true }).ParseDeclaration("border-bottom-color: var(--pale-grey);")

The same happens if I examine a document loaded with the following code, that contains a <style> node with similar css rules.

var config = AngleSharp.Configuration.Default.WithDefaultLoader(new LoaderOptions { IsResourceLoadingEnabled = true }).WithCss();
var context = BrowsingContext.New(config);
var document = context.OpenAsync(res => res.Content(File.ReadAllText(@"sample.html")));

Expected Behavior

longhand properties:

Name Value
border-bottom-width 1px
border-bottom-style solid
border-bottom-color var(--pale-grey)

single property:

Name Value
border-bottom-color var(--pale-grey)

Actual Behavior

Name Value
border-bottom-width
border-bottom-style
border-bottom-color

single property:

Name Value
border-bottom-color var(--pale-grey)

Possible Solution / Known Workarounds

No response

@csiga00 csiga00 added the bug label May 14, 2024
@FlorianRappl
Copy link
Contributor

What's missing is what version of AngleSharp.Css you are running. Please add it. Thanks!

@csiga00
Copy link
Author

csiga00 commented May 14, 2024

I'm new to github too :), so I added the version info into the description. Is it ok or should I have added it elsewhere?

(I didn't preview my original post, so after sending it, I noticed that white spaces have been collapsed between Name - Value "columns" in expected and actual behaviour)

Thanks!

@FlorianRappl
Copy link
Contributor

This is okay. Note that the current version is 1.0.0-beta.139, so I'd recommend updating. If the issue persists please write here, otherwise I'd close the issue.

@csiga00
Copy link
Author

csiga00 commented May 15, 2024

Thanks for the info! I installed the packages (AngleSharp and AngleSharp.Css) via Nuget manager in Visual Studio and with prerelease checked, it shows AngleSharp 1.1.2 and AngleSharp.Css 1.0.0-alpha-99 as latest versions, however I can see the mentioned newer releases on nuget.org. I'll try to install them somehow.

@csiga00
Copy link
Author

csiga00 commented May 15, 2024

I installed AngleSharp.Css 1.0.0-beta.139 with Package Manager Console successfully, but the issue seems to persist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants