diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
deleted file mode 100644
index 44871a98..00000000
--- a/.github/ISSUE_TEMPLATE/bug_report.md
+++ /dev/null
@@ -1,39 +0,0 @@
----
-name: Bug Report
-about: Create a report to help us improve
-title: ''
-labels: 'bug'
-assignees: ''
----
-
-# Bug Report
-
-## Prerequisites
-
-- [ ] Can you reproduce the problem in a [MWE](https://en.wikipedia.org/wiki/Minimal_working_example)?
-- [ ] Are you running the latest version of AngleSharp?
-- [ ] 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.Css` for CSS support)
-- [ ] Did you perform a search in the issues?
-
-For more information, see the `CONTRIBUTING` guide.
-
-## Description
-
-[Description of the bug]
-
-## Steps to Reproduce
-
-1. [First Step]
-2. [Second Step]
-3. [and so on...]
-
-**Expected behavior:** [What you expected to happen]
-
-**Actual behavior:** [What actually happened]
-
-**Environment details:** [OS, .NET Runtime, ...]
-
-## Possible Solution
-
-[Optionally, share your idea to fix the issue]
diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml
new file mode 100644
index 00000000..32f16a15
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/bug_report.yml
@@ -0,0 +1,69 @@
+name: Bug Report
+description: "Create a report to help us improve"
+labels: ["bug"]
+body:
+ - type: checkboxes
+ id: prerequisites
+ attributes:
+ label: Prerequisites
+ description: For more information, see the [CONTRIBUTING guide](https://github.com/AngleSharp/AngleSharp.Css/blob/devel/.github/CONTRIBUTING.md).
+ options:
+ - label: Can you reproduce the problem in a [MWE](https://en.wikipedia.org/wiki/Minimal_working_example)?
+ required: true
+ - label: Are you running the latest version of AngleSharp.Css?
+ required: true
+ - label: Did you check the FAQs to see if that helps you?
+ required: true
+ - label: Are you reporting to the correct repository? (there are multiple AngleSharp libraries, e.g., `AngleSharp.Xml` for Xml support)
+ required: true
+ - label: Did you perform a search in the issues?
+ required: true
+
+ - type: textarea
+ id: description
+ attributes:
+ label: Description
+ description: Share a clear and concise description of the problem.
+ placeholder: Description
+ validations:
+ required: true
+
+ - type: textarea
+ id: reproduction-steps
+ attributes:
+ label: Steps to Reproduce
+ description: |
+ Include minimal steps to reproduce the problem if possible. E.g.: the smallest possible code snippet; or a small project, with steps to run it. Make sure to include logs and exceptions as text rather than screenshots.
+ placeholder: Minimal Reproduction
+ validations:
+ required: true
+
+ - type: textarea
+ id: expected-behavior
+ attributes:
+ label: Expected Behavior
+ description: |
+ Provide a description of the expected behavior.
+ placeholder: Expected Behavior
+ validations:
+ required: true
+
+ - type: textarea
+ id: actual-behavior
+ attributes:
+ label: Actual Behavior
+ description: |
+ Provide a description of the actual behavior observed. If applicable, include the error messages and the exception stacktrace.
+ placeholder: Actual Behavior
+ validations:
+ required: true
+
+ - type: textarea
+ id: known-workarounds
+ attributes:
+ label: Possible Solution / Known Workarounds
+ description: |
+ Provide a description of any possible solution or known workarounds.
+ placeholder: Possible Solution / Known Workarounds
+ validations:
+ required: false
diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml
new file mode 100644
index 00000000..73d2a3a1
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/config.yml
@@ -0,0 +1,5 @@
+blank_issues_enabled: false
+contact_links:
+ - name: Documentation
+ url: https://anglesharp.github.io/
+ about: Read our comprehensive documentation
\ No newline at end of file
diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md
deleted file mode 100644
index 7722f052..00000000
--- a/.github/ISSUE_TEMPLATE/feature_request.md
+++ /dev/null
@@ -1,21 +0,0 @@
----
-name: Feature Request
-about: Suggest an idea for this project
-title: ''
-labels: 'enhancement'
-assignees: ''
----
-
-# New Feature Proposal
-
-## Description
-
-[Description of the proposed feature]
-
-## Background
-
-Provide any additional background for the feature. e.g., user scenarios.
-
-## Specification
-
-In case of updates that adhere to specification changes, please reference the used specification.
diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml
new file mode 100644
index 00000000..99fd75aa
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/feature_request.yml
@@ -0,0 +1,20 @@
+name: Feature Idea
+description: "Suggest an idea for this project"
+labels: ["enhancement"]
+body:
+ - type: textarea
+ attributes:
+ label: Description
+ description: What should the new feature do?
+ validations:
+ required: true
+
+ - type: textarea
+ attributes:
+ label: Background
+ description: Provide any additional background for the feature. e.g., user scenarios.
+
+ - type: textarea
+ attributes:
+ label: Specification
+ description: In case of updates that adhere to specification changes, please reference the used specification.
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index f01d24d3..efce7ef1 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -56,6 +56,7 @@ jobs:
dotnet-version: |
6.0.x
7.0.x
+ 8.0.x
- name: Build
run: ./build.sh
@@ -72,6 +73,7 @@ jobs:
dotnet-version: |
6.0.x
7.0.x
+ 8.0.x
- name: Build
run: |
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5ff21124..d7dbd41f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,32 @@
+# 1.0.0
+
+Released on Sunday, January 21 2024.
+
+- Updated to use AngleSharp 1.0 (#150)
+- Updated media parsing to media L4 spec (#133)
+- Updated naming of CSS values (e.g., `Color` to `CssColorValue`)
+- Fixed issue when updating shorthands with invalid values (#129)
+- Fixed issue with appended EOF character in `CssText` (#123)
+- Fixed missing semicolon in `@page` rule (#135)
+- Fixed integer serialization of keyframe stops (#128)
+- Fixed ordering of rows and columns in `grid` and `grid-gap` (#137)
+- Fixed inclusion of CSS from stylesheets (#116, #140)
+- Fixed style empty if `text-align` is `start` (#151)
+- Fixed computation of priority in CSS rules using multi selector
+- Fixed `GetInnerText` multi-line / text node behavior (#155) @Seyden
+- Fixed computation of relative (`em`) values to absolute (`px`) for `Length` (#136)
+- Added further compactification of CSS tuples (#89, #93)
+- Added new value types `CssPercentageValue`, `CssNumberValue`, and `CssIntegerValue`
+- Added support for CSS nesting in style rules (#148)
+- Added resolution of CSS variable names (#62)
+- Added support for 8-digit hex color codes (#132)
+- Added support for `margin-block` and `margin-inline` declarations
+- Added support for `padding-block` and `padding-inline` declarations
+- Added more CSSOM possibilities and helpers (#6)
+- Added parts of recent color spec update such as `rgb` with spaces (#131)
+- Added now Color L4 parsing with `hsl`, `hwb`, `lab`, `lch`, `oklab`, and `oklch`
+- Added support for recent CSS `list-type` values (#152)
+
# 0.17.0
Released on Sunday, January 15 2023.
diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md
index 25959ec7..0058dde2 100644
--- a/CONTRIBUTORS.md
+++ b/CONTRIBUTORS.md
@@ -16,6 +16,8 @@ AngleSharp.Css contains code written by (in order of first pull request / commit
* [Bastian Buchholz](https://github.com/campersau)
* [Fraaankes](https://github.com/Fraaankes)
* [Eric Mutta](https://github.com/ericmutta)
+* [Seyden](https://github.com/Seyden)
+* [Dave Dunkin](https://github.com/ddunkin)
Without these awesome people AngleSharp.Css could not exist. Thanks to everyone for your contributions! :beers:
diff --git a/LICENSE b/LICENSE
index 470f190b..b64c5a7f 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)
-Copyright (c) 2013 - 2023 AngleSharp
+Copyright (c) 2013 - 2025 AngleSharp
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/README.md b/README.md
index 5eee1792..431b3aa8 100644
--- a/README.md
+++ b/README.md
@@ -97,12 +97,4 @@ This project is supported by the [.NET Foundation](https://dotnetfoundation.org)
## License
-The MIT License (MIT)
-
-Copyright (c) 2016 - 2022 AngleSharp
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+AngleSharp.Css is released using the MIT license. For more information see the [license file](./LICENSE).
diff --git a/docs/README.md b/docs/README.md
index 0d8585c9..29f5ccde 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -2,4 +2,8 @@
We have more detailed information regarding the following subjects:
+- [Getting Started](general/01-Basics.md)
+- [Value Model](general/02-Values.md)
- [API Documentation](tutorials/01-API.md)
+- [Examples](tutorials/02-Examples.md)
+- [FAQ](tutorials/03-Questions.md)
diff --git a/nuke/Build.cs b/nuke/Build.cs
index b08f6bde..a186fdf3 100644
--- a/nuke/Build.cs
+++ b/nuke/Build.cs
@@ -89,11 +89,11 @@ protected override void OnBuildInitialized()
if (ScheduledTargets.Contains(Default))
{
- Version = $"{Version}-ci-{buildNumber}";
+ Version = $"{Version}-ci.{buildNumber}";
}
else if (ScheduledTargets.Contains(PrePublish))
{
- Version = $"{Version}-alpha-{buildNumber}";
+ Version = $"{Version}-beta.{buildNumber}";
}
}
diff --git a/nuke/ReleaseNotesParser.cs b/nuke/ReleaseNotesParser.cs
index 4b00a073..d911c90b 100644
--- a/nuke/ReleaseNotesParser.cs
+++ b/nuke/ReleaseNotesParser.cs
@@ -17,16 +17,6 @@
///
public sealed class ReleaseNotesParser
{
- private readonly Regex _versionRegex;
-
- ///
- /// Initializes a new instance of the class.
- ///
- public ReleaseNotesParser()
- {
- _versionRegex = new Regex(@"(?\d+(\s*\.\s*\d+){0,3})(?-[a-z][0-9a-z-]*)?");
- }
-
///
/// Parses all release notes.
///
diff --git a/src/AngleSharp.Css.Tests/AngleSharp.Css.Tests.csproj b/src/AngleSharp.Css.Tests/AngleSharp.Css.Tests.csproj
index 8bf7df15..b61b451a 100644
--- a/src/AngleSharp.Css.Tests/AngleSharp.Css.Tests.csproj
+++ b/src/AngleSharp.Css.Tests/AngleSharp.Css.Tests.csproj
@@ -16,7 +16,7 @@
-
+
diff --git a/src/AngleSharp.Css.Tests/CssConstructionFunctions.cs b/src/AngleSharp.Css.Tests/CssConstructionFunctions.cs
index e62c5ee5..dd915242 100644
--- a/src/AngleSharp.Css.Tests/CssConstructionFunctions.cs
+++ b/src/AngleSharp.Css.Tests/CssConstructionFunctions.cs
@@ -2,6 +2,7 @@ namespace AngleSharp.Css.Tests
{
using AngleSharp.Css.Dom;
using AngleSharp.Css.Parser;
+ using AngleSharp.Css.Values;
using AngleSharp.Html.Dom;
using AngleSharp.Html.Parser;
using System;
@@ -70,7 +71,6 @@ internal static CssProperty ParseDeclaration(String source, CssParserOptions opt
internal static CssStyleDeclaration ParseDeclarations(String declarations)
{
var context = BrowsingContext.New(Configuration.Default.WithCss());
- var parser = context.GetService();
var style = new CssStyleDeclaration(context);
style.Update(declarations);
return style;
@@ -93,7 +93,7 @@ internal static CssImportRule ParseImportRule(String source)
internal static Predicate CreateValidator(String name, String value)
{
var validator = CreateMediaFeatureValidator(name);
- var feature = new MediaFeature(name, value);
+ var feature = new MediaFeature(name, new CssAnyValue(value));
return device => validator.Validate(feature, device);
}
diff --git a/src/AngleSharp.Css.Tests/Declarations/CssBackgroundProperty.cs b/src/AngleSharp.Css.Tests/Declarations/CssBackgroundProperty.cs
index bb5c2d02..03d9da7c 100644
--- a/src/AngleSharp.Css.Tests/Declarations/CssBackgroundProperty.cs
+++ b/src/AngleSharp.Css.Tests/Declarations/CssBackgroundProperty.cs
@@ -6,6 +6,30 @@ namespace AngleSharp.Css.Tests.Declarations
[TestFixture]
public class CssBackgroundPropertyTests
{
+ [Test]
+ public void CssBackgroundSizeCoverTest()
+ {
+ var snippet = "background-size : cover";
+ var property = ParseDeclaration(snippet);
+ Assert.AreEqual("background-size", property.Name);
+ Assert.IsFalse(property.IsImportant);
+ Assert.IsFalse(property.IsInherited);
+ Assert.IsTrue(property.HasValue);
+ Assert.AreEqual("cover", property.Value);
+ }
+
+ [Test]
+ public void CssBackgroundSizeContainTest()
+ {
+ var snippet = "background-size : contain";
+ var property = ParseDeclaration(snippet);
+ Assert.AreEqual("background-size", property.Name);
+ Assert.IsFalse(property.IsImportant);
+ Assert.IsFalse(property.IsInherited);
+ Assert.IsTrue(property.HasValue);
+ Assert.AreEqual("contain", property.Value);
+ }
+
[Test]
public void CssBackgroundAttachmentScrollLegal()
{
diff --git a/src/AngleSharp.Css.Tests/Declarations/CssGridProperty.cs b/src/AngleSharp.Css.Tests/Declarations/CssGridProperty.cs
index 7d366d01..e75811f9 100644
--- a/src/AngleSharp.Css.Tests/Declarations/CssGridProperty.cs
+++ b/src/AngleSharp.Css.Tests/Declarations/CssGridProperty.cs
@@ -534,7 +534,7 @@ public void CssGridAreaTextValueLegal1()
var css = ParseStyleSheet(source);
var text = css.Rules[0].CssText;
- var expected = "#nav-header { grid-area: aaa / aaa / aaa / aaa }";
+ var expected = "#nav-header { grid-area: aaa }";
Assert.AreEqual(expected, text);
}
@@ -909,5 +909,21 @@ public void CssGridTemplateLonghands_Issue68()
var style = ParseDeclarations(snippet);
Assert.AreEqual("grid-template: none", style.CssText);
}
+
+ [Test]
+ public void CssGridPreservesParts_Issue137()
+ {
+ var snippet = "grid: 10px / 80px";
+ var style = ParseDeclarations(snippet);
+ Assert.AreEqual("grid: 10px / 80px", style.CssText);
+ }
+
+ [Test]
+ public void CssGridGapPreservesParts_Issue137()
+ {
+ var snippet = "grid-gap: 10px 80px";
+ var style = ParseDeclarations(snippet);
+ Assert.AreEqual("grid-gap: 10px 80px", style.CssText);
+ }
}
}
diff --git a/src/AngleSharp.Css.Tests/Declarations/CssListProperty.cs b/src/AngleSharp.Css.Tests/Declarations/CssListProperty.cs
index 1fca39c3..e23f95ac 100644
--- a/src/AngleSharp.Css.Tests/Declarations/CssListProperty.cs
+++ b/src/AngleSharp.Css.Tests/Declarations/CssListProperty.cs
@@ -1,4 +1,4 @@
-namespace AngleSharp.Css.Tests.Declarations
+namespace AngleSharp.Css.Tests.Declarations
{
using NUnit.Framework;
using static CssConstructionFunctions;
@@ -125,14 +125,15 @@ public void CssListStyleTypeDecimalLeadingZeroLegal()
}
[Test]
- public void CssListStyleTypeNumberIllegal()
+ public void CssListStyleTypeSomeValueLegal()
{
var snippet = "list-style-type: number ";
var property = ParseDeclaration(snippet);
Assert.AreEqual("list-style-type", property.Name);
Assert.IsFalse(property.IsImportant);
- Assert.IsTrue(property.IsInherited);
- Assert.IsFalse(property.HasValue);
+ Assert.IsFalse(property.IsInherited);
+ Assert.IsTrue(property.HasValue);
+ Assert.AreEqual("number", property.Value);
}
[Test]
@@ -277,5 +278,94 @@ public void CssCounterIncrementLegal()
Assert.IsTrue(property.HasValue);
Assert.AreEqual("chapter 1 section 2 page 1", property.Value);
}
+
+ [Test]
+ public void CssListStyleStringValue_Issue152()
+ {
+ var snippet = "list-style-type: \"-\"";
+ var property = ParseDeclaration(snippet);
+ Assert.AreEqual("list-style-type", property.Name);
+ Assert.IsTrue(property.HasValue);
+ Assert.AreEqual("\"-\"", property.Value);
+ }
+
+ [Test]
+ public void CssListStyleKannada_Issue152()
+ {
+ var snippet = "list-style-type: kannada";
+ var property = ParseDeclaration(snippet);
+ Assert.AreEqual("list-style-type", property.Name);
+ Assert.IsTrue(property.HasValue);
+ Assert.AreEqual("kannada", property.Value);
+ }
+
+ [Test]
+ public void CssListStyleTradChineseInformal_Issue152()
+ {
+ var snippet = "list-style-type: trad-chinese-informal;";
+ var property = ParseDeclaration(snippet);
+ Assert.AreEqual("list-style-type", property.Name);
+ Assert.IsTrue(property.HasValue);
+ Assert.AreEqual("trad-chinese-informal", property.Value);
+ }
+
+ [Test]
+ public void CssListStyleGeorgian_Issue152()
+ {
+ var snippet = "list-style-type: georgian";
+ var property = ParseDeclaration(snippet);
+ Assert.AreEqual("list-style-type", property.Name);
+ Assert.IsTrue(property.HasValue);
+ Assert.AreEqual("georgian", property.Value);
+ }
+
+ [Test]
+ public void CssListStyleDecimal_Issue152()
+ {
+ var snippet = "list-style-type: decimal";
+ var property = ParseDeclaration(snippet);
+ Assert.AreEqual("list-style-type", property.Name);
+ Assert.IsTrue(property.HasValue);
+ Assert.AreEqual("decimal", property.Value);
+ }
+
+ [Test]
+ public void CssListStyleSquare_Issue152()
+ {
+ var snippet = "list-style-type: square";
+ var property = ParseDeclaration(snippet);
+ Assert.AreEqual("list-style-type", property.Name);
+ Assert.IsTrue(property.HasValue);
+ Assert.AreEqual("square", property.Value);
+ }
+
+ [Test]
+ public void CssListStyleCircle_Issue152()
+ {
+ var snippet = "list-style-type: circle";
+ var property = ParseDeclaration(snippet);
+ Assert.AreEqual("list-style-type", property.Name);
+ Assert.IsTrue(property.HasValue);
+ Assert.AreEqual("circle", property.Value);
+ }
+
+ [Test]
+ public void CssListStyleSymbolsFunction_Issue152()
+ {
+ var snippet = "list-style-type: symbols(cyclic \"*\" \"†\" \"‡\")";
+ var property = ParseDeclaration(snippet);
+ Assert.AreEqual("list-style-type", property.Name);
+ Assert.IsTrue(property.HasValue);
+ Assert.AreEqual("symbols(cyclic \"*\" \"†\" \"‡\")", property.Value);
+ }
+
+ [Test]
+ public void CssListStyleSymbolsFailingForWrongType_Issue152()
+ {
+ var snippet = "list-style-type: symbols(foo \"*\" \"†\" \"‡\")";
+ var property = ParseDeclaration(snippet);
+ Assert.AreEqual("list-style-type", property.Name);
+ Assert.IsFalse(property.HasValue);
+ }
}
}
diff --git a/src/AngleSharp.Css.Tests/Declarations/CssTextProperty.cs b/src/AngleSharp.Css.Tests/Declarations/CssTextProperty.cs
index 545cca7c..b8dd8507 100644
--- a/src/AngleSharp.Css.Tests/Declarations/CssTextProperty.cs
+++ b/src/AngleSharp.Css.Tests/Declarations/CssTextProperty.cs
@@ -690,6 +690,39 @@ public void CssOverflowWrapAlternateNameNoneIllegal()
Assert.IsFalse(property.IsInherited);
Assert.IsFalse(property.IsImportant);
Assert.IsFalse(property.HasValue);
- }
- }
+ }
+
+ [Test]
+ public void CssTextAlignLegalStart_Issue151()
+ {
+ var snippet = "text-align:start";
+ var property = ParseDeclaration(snippet);
+ Assert.AreEqual("text-align", property.Name);
+ Assert.IsTrue(property.HasValue);
+ Assert.IsFalse(property.IsImportant);
+ Assert.IsFalse(property.IsInherited);
+ Assert.AreEqual("start", property.Value);
+ }
+
+ [Test]
+ public void CssTextAlignLegalJustifyAll_Issue151()
+ {
+ var snippet = "text-align:justify-all";
+ var property = ParseDeclaration(snippet);
+ Assert.AreEqual("text-align", property.Name);
+ Assert.IsTrue(property.HasValue);
+ Assert.IsFalse(property.IsImportant);
+ Assert.IsFalse(property.IsInherited);
+ Assert.AreEqual("justify-all", property.Value);
+ }
+
+ [Test]
+ public void CssTextAlignIllegalJustifyNone_Issue151()
+ {
+ var snippet = "text-align:justify-none";
+ var property = ParseDeclaration(snippet);
+ Assert.AreEqual("text-align", property.Name);
+ Assert.IsFalse(property.HasValue);
+ }
+ }
}
diff --git a/src/AngleSharp.Css.Tests/Declarations/CssVariables.cs b/src/AngleSharp.Css.Tests/Declarations/CssVariables.cs
index f3ba1fed..e0315c71 100644
--- a/src/AngleSharp.Css.Tests/Declarations/CssVariables.cs
+++ b/src/AngleSharp.Css.Tests/Declarations/CssVariables.cs
@@ -59,7 +59,7 @@ public void LegitVariableReferenceWithFallback()
Assert.IsNotNull(variable);
Assert.AreEqual(1, variable.References.Length);
Assert.AreEqual("--my-bar", variable.References[0].VariableName);
- Assert.AreEqual("24px", variable.References[0].DefaultValue);
+ Assert.AreEqual("24px", variable.References[0].DefaultValue.CssText);
}
[Test]
@@ -72,7 +72,7 @@ public void LegitVariableReferenceWithFallbackContainingComma()
Assert.IsNotNull(variable);
Assert.AreEqual(1, variable.References.Length);
Assert.AreEqual("--color", variable.References[0].VariableName);
- Assert.AreEqual("red, blue", variable.References[0].DefaultValue);
+ Assert.AreEqual("red, blue", variable.References[0].DefaultValue.CssText);
}
[Test]
@@ -113,7 +113,7 @@ public void LegitMultipleVariableReferenceInBorderShorthand()
Assert.AreEqual("--width", variable.References[0].VariableName);
Assert.IsNull(variable.References[0].DefaultValue);
Assert.AreEqual("--color", variable.References[1].VariableName);
- Assert.AreEqual("black", variable.References[1].DefaultValue);
+ Assert.AreEqual("black", variable.References[1].DefaultValue.CssText);
}
}
}
diff --git a/src/AngleSharp.Css.Tests/Extensions/AnalysisWindow.cs b/src/AngleSharp.Css.Tests/Extensions/AnalysisWindow.cs
index d842410e..d755ac7a 100644
--- a/src/AngleSharp.Css.Tests/Extensions/AnalysisWindow.cs
+++ b/src/AngleSharp.Css.Tests/Extensions/AnalysisWindow.cs
@@ -279,15 +279,134 @@ public void GetCascadedValueOfTextTransformFromElementStyle()
Assert.AreEqual("uppercase", styleNormal.GetTextTransform());
}
+ [Test]
+ public void GetCascadedValueOfTextTransformFromElementStyleWithElementApi()
+ {
+ var sourceCode = "
Bold text";
+
+ var document = ParseDocument(sourceCode);
+ var element = document.QuerySelector("span");
+ var styleNormal = element.ComputeStyle();
+ Assert.IsNotNull(styleNormal);
+ Assert.AreEqual("uppercase", styleNormal.GetTextTransform());
+ }
+
[Test]
public async Task NullSelectorStillWorks_Issue52()
{
var sheet = ParseStyleSheet("a {}");
var document = await sheet.Context.OpenAsync(res => res.Content(""));
- sheet.Add(new CssStyleRule(sheet));
var sc = new StyleCollection(new[] { sheet }, new DefaultRenderDevice());
var decl = sc.ComputeCascadedStyle(document.Body);
Assert.IsNotNull(decl);
}
+
+ [Test]
+ public async Task PriorityInMultiSelectorIsEvaluatedPerMatch()
+ {
+ var sheet = ParseStyleSheet(@"#target {color: blue} h3, #nottarget { color: purple; } ");
+ var document = await sheet.Context.OpenAsync(res => res.Content(@"
Test
"));
+ var sc = new StyleCollection(new[] { sheet }, new DefaultRenderDevice());
+ var style = sc.ComputeCascadedStyle(document.QuerySelector("h3"));
+ Assert.AreEqual("rgba(0, 0, 255, 1)", style.GetColor());
+ }
+
+ [Test]
+ public async Task ComputesAbsoluteValuesFromRelative_Issue136()
+ {
+ var sheet = ParseStyleSheet(@"p { font-size: 1.5em }");
+ var document = await sheet.Context.OpenAsync(res => res.Content(@"
This is only a test.
"));
+ var sc = new StyleCollection(new[] { sheet }, new DefaultRenderDevice());
+ var style = sc.ComputeDeclarations(document.QuerySelector("span"));
+ Assert.AreEqual("24px", style.GetFontSize());
+ }
+
+ [Test]
+ public async Task ResolvesCssVariables_Issue62()
+ {
+ var sheet = ParseStyleSheet(@"
+ :root {
+ --color: #FFFFFF;
+ }
+
+ p {
+ color: var(--color);
+ }");
+ var document = await sheet.Context.OpenAsync(res => res.Content(@"
This is a test
"));
+ var sc = new StyleCollection(new[] { sheet }, new DefaultRenderDevice());
+ var style = sc.ComputeDeclarations(document.QuerySelector("p"));
+ Assert.AreEqual("rgba(255, 255, 255, 1)", style.GetColor());
+ }
+
+ [Test]
+ public async Task ResolvesCssVariablesWithUnusedFallback_Issue62()
+ {
+ var sheet = ParseStyleSheet(@"
+ :root {
+ --color: #FFFFFF;
+ }
+
+ p {
+ color: var(--color, green);
+ }");
+ var document = await sheet.Context.OpenAsync(res => res.Content(@"
This is a test
"));
+ var sc = new StyleCollection(new[] { sheet }, new DefaultRenderDevice());
+ var style = sc.ComputeDeclarations(document.QuerySelector("p"));
+ Assert.AreEqual("rgba(255, 255, 255, 1)", style.GetColor());
+ }
+
+ [Test]
+ public async Task ResolvesCssVariablesWithUsedFallback_Issue62()
+ {
+ var sheet = ParseStyleSheet(@"
+ :root {}
+
+ p {
+ color: var(--color, green);
+ }");
+ var document = await sheet.Context.OpenAsync(res => res.Content(@"
This is a test
"));
+ var sc = new StyleCollection(new[] { sheet }, new DefaultRenderDevice());
+ var style = sc.ComputeDeclarations(document.QuerySelector("p"));
+ Assert.AreEqual("rgba(0, 128, 0, 1)", style.GetColor());
+ }
+
+ [Test]
+ public async Task ResolvesCssVariablesWithUsedFallbackVarReference_Issue62()
+ {
+ var sheet = ParseStyleSheet(@"
+ :root {
+ --defaultColor: green;
+ }
+
+ p {
+ color: var(--color, var(--defaultColor));
+ }");
+ var document = await sheet.Context.OpenAsync(res => res.Content(@"
This is a test
"));
+ var sc = new StyleCollection(new[] { sheet }, new DefaultRenderDevice());
+ var style = sc.ComputeDeclarations(document.QuerySelector("p"));
+ Assert.AreEqual("rgba(0, 128, 0, 1)", style.GetColor());
+ }
+
+ [Test]
+ public async Task ResolvesCssVariablesWithCascade_Issue62()
+ {
+ var sheet = ParseStyleSheet(@"
+ :root {
+ --color: blue;
+ --defaultColor: red;
+ }
+
+ body {
+ --color: green;
+ }
+
+ p {
+ color: var(--color, var(--defaultColor));
+ }");
+ var document = await sheet.Context.OpenAsync(res => res.Content(@"
This is a test
"));
+ var sc = new StyleCollection(new[] { sheet }, new DefaultRenderDevice());
+ var style = sc.ComputeDeclarations(document.QuerySelector("p"));
+ Assert.AreEqual("rgba(0, 128, 0, 1)", style.GetColor());
+ }
}
}
diff --git a/src/AngleSharp.Css.Tests/Extensions/Elements.cs b/src/AngleSharp.Css.Tests/Extensions/Elements.cs
index 0134dc61..c5dff0e6 100644
--- a/src/AngleSharp.Css.Tests/Extensions/Elements.cs
+++ b/src/AngleSharp.Css.Tests/Extensions/Elements.cs
@@ -39,6 +39,7 @@ public async Task DownloadResources()
};
var config = Configuration.Default
.WithDefaultLoader(loaderOptions)
+ .WithRenderDevice()
.WithCss();
var document = "".ToHtmlDocument(config);
var tree = document.DefaultView.Render();
diff --git a/src/AngleSharp.Css.Tests/Extensions/InnerText.cs b/src/AngleSharp.Css.Tests/Extensions/InnerText.cs
index ab55c6c9..f12fb385 100644
--- a/src/AngleSharp.Css.Tests/Extensions/InnerText.cs
+++ b/src/AngleSharp.Css.Tests/Extensions/InnerText.cs
@@ -37,6 +37,9 @@ public void SetInnerText(String fixture, String expectedInnerText, String expect
// paragraph
[TestCase("
", "test1\ntest2\ntest3")]
[TestCase(@"test1test2test3", "test1\ntest2\ntest3")]
diff --git a/src/AngleSharp.Css.Tests/Extensions/Nesting.cs b/src/AngleSharp.Css.Tests/Extensions/Nesting.cs
new file mode 100644
index 00000000..577f386d
--- /dev/null
+++ b/src/AngleSharp.Css.Tests/Extensions/Nesting.cs
@@ -0,0 +1,118 @@
+namespace AngleSharp.Css.Tests.Extensions
+{
+ using AngleSharp.Css.Dom;
+ using AngleSharp.Dom;
+ using NUnit.Framework;
+ using static CssConstructionFunctions;
+
+ [TestFixture]
+ public class NestingTests
+ {
+ [Test]
+ public void SimpleSelectorNestingImplicit()
+ {
+ var source = @"
Larger and green";
+ var document = ParseDocument(source);
+ var window = document.DefaultView;
+ var element = document.QuerySelector(".bar");
+ var style = window.GetComputedStyle(element);
+
+ Assert.AreEqual("22.4px", style.GetFontSize());
+ }
+
+ [Test]
+ public void SimpleSelectorNestingImplicitDeclarations()
+ {
+ var source = @"
Larger and green";
+ var document = ParseDocument(source);
+ var window = document.DefaultView;
+ var element = document.QuerySelector(".bar");
+ var styleCollection = window.GetStyleCollection();
+ var style = styleCollection.GetDeclarations(element);
+
+ Assert.AreEqual("1.4rem", style.GetFontSize());
+ }
+
+ [Test]
+ public void SimpleSelectorNestingExplicit()
+ {
+ var source = @"
Larger and green";
+ var document = ParseDocument(source);
+ var window = document.DefaultView;
+ var element = document.QuerySelector(".bar");
+ var style = window.GetComputedStyle(element);
+
+ Assert.AreEqual("22.4px", style.GetFontSize());
+ }
+
+ [Test]
+ public void SimpleSelectorNestingOverwritten()
+ {
+ var source = @"
Larger and green";
+ var document = ParseDocument(source);
+ var window = document.DefaultView;
+ var element = document.QuerySelector(".bar");
+ var style = window.GetComputedStyle(element);
+
+ Assert.AreEqual("22.4px", style.GetFontSize());
+ }
+
+ [Test]
+ public void CombinedSelectorNesting()
+ {
+ var source = @"
green";
+ var document = ParseDocument(source);
+ var window = document.DefaultView;
+ var element = document.QuerySelector(".bar");
+ var style = window.GetComputedStyle(element);
+
+ Assert.AreEqual("rgba(0, 128, 0, 1)", style.GetColor());
+ }
+
+ [Test]
+ public void ReversedSelectorNesting()
+ {
+ var source = @"
green";
+ var document = ParseDocument(source);
+ var window = document.DefaultView;
+ var element = document.QuerySelector("li");
+ var style = window.GetComputedStyle(element);
+
+ Assert.AreEqual("rgba(0, 128, 0, 1)", style.GetColor());
+ }
+ }
+}
diff --git a/src/AngleSharp.Css.Tests/Functions/CssColorFunction.cs b/src/AngleSharp.Css.Tests/Functions/CssColorFunction.cs
index 7396400c..cf36e11b 100644
--- a/src/AngleSharp.Css.Tests/Functions/CssColorFunction.cs
+++ b/src/AngleSharp.Css.Tests/Functions/CssColorFunction.cs
@@ -19,6 +19,171 @@ public void ColorNotParsedCorrectly_Issue109()
var color = s.GetColor();
Assert.AreEqual("rgba(0, 17, 0, 1)", color);
}
+
+ [Test]
+ public void ParseRgbWithSpacesL4_Issue131()
+ {
+ var html = @"
Text
";
+ var dom = ParseDocument(html);
+ var p = dom.QuerySelector("p");
+ var s = p.GetStyle();
+ var color = s.GetColor();
+ Assert.AreEqual("rgba(255, 122, 127, 0.8)", color);
+ }
+
+ [Test]
+ public void ParseRgbWithSpacesInPercentL4_Issue131()
+ {
+ var html = @"
Text
";
+ var dom = ParseDocument(html);
+ var p = dom.QuerySelector("p");
+ var s = p.GetStyle();
+ var color = s.GetColor();
+ Assert.AreEqual("rgba(255, 26, 128, 0.7)", color);
+ }
+
+ [Test]
+ public void ParseRgbWithSpacesAndNoneL4_Issue131()
+ {
+ var html = @"
Text
";
+ var dom = ParseDocument(html);
+ var p = dom.QuerySelector("p");
+ var s = p.GetStyle();
+ var color = s.GetColor();
+ Assert.AreEqual("rgba(255, 0, 128, 0.35)", color);
+ }
+
+ [Test]
+ public void ParseOklabToRgb_First()
+ {
+ var html = @"
Text
";
+ var dom = ParseDocument(html);
+ var p = dom.QuerySelector("p");
+ var s = p.GetStyle();
+ var color = s.GetColor();
+ Assert.AreEqual("rgba(125, 35, 40, 1)", color);
+ }
+
+ [Test]
+ public void ParseOklabToRgb_Second()
+ {
+ var html = @"
Text
";
+ var dom = ParseDocument(html);
+ var p = dom.QuerySelector("p");
+ var s = p.GetStyle();
+ var color = s.GetColor();
+ Assert.AreEqual("rgba(198, 93, 7, 1)", color);
+ }
+
+ [Test]
+ public void ParseOklabToRgb_Alpha()
+ {
+ var html = @"
Text
";
+ var dom = ParseDocument(html);
+ var p = dom.QuerySelector("p");
+ var s = p.GetStyle();
+ var color = s.GetColor();
+ Assert.AreEqual("rgba(198, 93, 7, 0.5)", color);
+ }
+
+ [Test]
+ public void ParseOklchToRgb_First()
+ {
+ var html = @"
Text
";
+ var dom = ParseDocument(html);
+ var p = dom.QuerySelector("p");
+ var s = p.GetStyle();
+ var color = s.GetColor();
+ Assert.AreEqual("rgba(125, 35, 40, 1)", color);
+ }
+
+ [Test]
+ public void ParseOklchToRgb_Second()
+ {
+ var html = @"
Text
";
+ var dom = ParseDocument(html);
+ var p = dom.QuerySelector("p");
+ var s = p.GetStyle();
+ var color = s.GetColor();
+ Assert.AreEqual("rgba(198, 93, 7, 1)", color);
+ }
+
+ [Test]
+ public void ParseOklchToRgb_Alpha()
+ {
+ var html = @"
Text
";
+ var dom = ParseDocument(html);
+ var p = dom.QuerySelector("p");
+ var s = p.GetStyle();
+ var color = s.GetColor();
+ Assert.AreEqual("rgba(198, 93, 7, 0.5)", color);
+ }
+
+ [Test]
+ public void ParseLabToRgb_First()
+ {
+ var html = @"
Text
";
+ var dom = ParseDocument(html);
+ var p = dom.QuerySelector("p");
+ var s = p.GetStyle();
+ var color = s.GetColor();
+ Assert.AreEqual("rgba(125, 35, 40, 1)", color);
+ }
+
+ [Test]
+ public void ParseLabToRgb_Second()
+ {
+ var html = @"
Text
";
+ var dom = ParseDocument(html);
+ var p = dom.QuerySelector("p");
+ var s = p.GetStyle();
+ var color = s.GetColor();
+ Assert.AreEqual("rgba(198, 93, 6, 1)", color);
+ }
+
+ [Test]
+ public void ParseLabToRgb_Alpha()
+ {
+ var html = @"
Text
";
+ var dom = ParseDocument(html);
+ var p = dom.QuerySelector("p");
+ var s = p.GetStyle();
+ var color = s.GetColor();
+ Assert.AreEqual("rgba(198, 93, 6, 0.5)", color);
+ }
+
+ [Test]
+ public void ParseLchToRgb_First()
+ {
+ var html = @"
Text
";
+ var dom = ParseDocument(html);
+ var p = dom.QuerySelector("p");
+ var s = p.GetStyle();
+ var color = s.GetColor();
+ Assert.AreEqual("rgba(125, 35, 40, 1)", color);
+ }
+
+ [Test]
+ public void ParseLchToRgb_Second()
+ {
+ var html = @"
Text
";
+ var dom = ParseDocument(html);
+ var p = dom.QuerySelector("p");
+ var s = p.GetStyle();
+ var color = s.GetColor();
+ Assert.AreEqual("rgba(198, 93, 6, 1)", color);
+ }
+
+ [Test]
+ public void ParseLchToRgb_Alpha()
+ {
+ var html = @"
Text
";
+ var dom = ParseDocument(html);
+ var p = dom.QuerySelector("p");
+ var s = p.GetStyle();
+ var color = s.GetColor();
+ Assert.AreEqual("rgba(198, 93, 6, 0.5)", color);
+ }
}
}
diff --git a/src/AngleSharp.Css.Tests/Library/ComputedStyle.cs b/src/AngleSharp.Css.Tests/Library/ComputedStyle.cs
new file mode 100644
index 00000000..6ee3f880
--- /dev/null
+++ b/src/AngleSharp.Css.Tests/Library/ComputedStyle.cs
@@ -0,0 +1,29 @@
+namespace AngleSharp.Css.Tests.Library
+{
+ using AngleSharp.Dom;
+ using AngleSharp.Html.Dom;
+ using NUnit.Framework;
+ using System.Threading.Tasks;
+
+ [TestFixture]
+ public class ComputedStyleTests
+ {
+ [Test]
+ public async Task TransformEmToPx_Issue136()
+ {
+ // .With()
+ var config = Configuration.Default.WithCss();
+ var context = BrowsingContext.New(config);
+ var source = "