Skip to content

Commit

Permalink
Finished initial implementation of rules #102
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl committed Jan 15, 2023
1 parent d1e03ff commit 24d9755
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Released on Sunday, January 15 2023.

- Updated build system to use NUKE instead of CAKE
- Dropped .NET Framework 4.6
- Updated to use AngleSharp 0.17
- Updated micro parser API to be public (#111)
Expand Down
6 changes: 6 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ AngleSharp.Css contains code written by (in order of first pull request / commit
* [Tom Hazell](https://github.com/The-Nutty)
* [Michael Ganss](https://github.com/mganss)
* [Gérald Barré](https://github.com/meziantou)
* [Shesh](https://github.com/sheshnathverma)
* [Martin Welsch](https://github.com/MartinWelsch)
* [Jason Nelson](https://github.com/iamcarbon)
* [Bastian Buchholz](https://github.com/campersau)
* [Fraaankes](https://github.com/Fraaankes)
* [Eric Mutta](https://github.com/ericmutta)

Without these awesome people AngleSharp.Css could not exist. Thanks to everyone for your contributions! :beers:

Expand Down
14 changes: 14 additions & 0 deletions src/AngleSharp.Css.Tests/CssConstructionFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,19 @@ internal static Predicate<IRenderDevice> CreateValidator(String name, String val
var feature = new MediaFeature(name, value);
return device => validator.Validate(feature, device);
}

internal static CssFontFeatureValuesRule ParseFontFeatureValuesRule(String source)
{
ICssParser parser = new CssParser();
var sheet = parser.ParseStyleSheet(String.Empty);
return parser.ParseRule(sheet, source) as CssFontFeatureValuesRule;
}

internal static CssCounterStyleRule ParseCounterStyleRule(String source)
{
ICssParser parser = new CssParser();
var sheet = parser.ParseStyleSheet(String.Empty);
return parser.ParseRule(sheet, source) as CssCounterStyleRule;
}
}
}
18 changes: 18 additions & 0 deletions src/AngleSharp.Css.Tests/Rules/CssCounterStyleRule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace AngleSharp.Css.Tests.Rules
{
using AngleSharp.Dom;
using NUnit.Framework;
using static CssConstructionFunctions;

[TestFixture]
public class CssCounterStyleRuleTests
{
[Test]
public void CssCounterStyleThumbsIntroExample()
{
var source = "@counter-style thumbs {\n system: cyclic;\n symbols: \"\"\\1F44D\"\";\n suffix: \"\" \"\";\n }";
var rule = ParseCounterStyleRule(source);
Assert.AreEqual("thumbs", rule.StyleName);
}
}
}
18 changes: 18 additions & 0 deletions src/AngleSharp.Css.Tests/Rules/CssFontFeatureValuesRule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace AngleSharp.Css.Tests.Rules
{
using AngleSharp.Dom;
using NUnit.Framework;
using static CssConstructionFunctions;

[TestFixture]
public class CssFontFeatureValuesRuleTests
{
[Test]
public void CssFontFeaturesValuesForSomeIntroExample()
{
var source = "@font-feature-values Font One {\n @styleset {\n nice-style: 12;\n }\n }";
var rule = ParseFontFeatureValuesRule(source);
Assert.AreEqual("Font One", rule.FamilyName);
}
}
}
2 changes: 1 addition & 1 deletion src/AngleSharp.Css.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<copyright>Copyright 2016-2023, AngleSharp</copyright>
<tags>html html5 css css3 dom styling library anglesharp angle</tags>
<dependencies>
<dependency id="AngleSharp" version="0.17" />
<dependency id="AngleSharp" version="[0.17.0,0.18.0)" />
</dependencies>
</metadata>
</package>
27 changes: 23 additions & 4 deletions src/AngleSharp.Css/Parser/CssBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,15 +324,34 @@ private CssSupportsRule CreateSupports(CssSupportsRule rule, CssToken current)

private CssFontFeatureValuesRule CreateFontFeatureValues(CssFontFeatureValuesRule rule, CssToken current)
{
CollectTrivia(ref current);
//rule.FamilyName =
var token = NextToken();
CollectTrivia(ref token);
rule.FamilyName = GetArgument(ref token);

if (token.Type == CssTokenType.CurlyBracketOpen)
{
JumpToRuleEnd(ref token);
return rule;
}

SkipDeclarations(token);
return null;
}

private CssCounterStyleRule CreateCounterStyle(CssCounterStyleRule rule, CssToken current)
{
CollectTrivia(ref current);
return null;
var token = NextToken();
CollectTrivia(ref token);
rule.StyleName = GetArgument(ref token);

if (token.Type != CssTokenType.CurlyBracketOpen)
{
SkipDeclarations(token);
return null;
}

FillDeclarations(rule);
return rule;
}

public CssStyleRule CreateStyle(CssStyleRule rule, CssToken current)
Expand Down

0 comments on commit 24d9755

Please sign in to comment.