Skip to content

Commit 24d9755

Browse files
committed
Finished initial implementation of rules #102
1 parent d1e03ff commit 24d9755

File tree

7 files changed

+81
-5
lines changed

7 files changed

+81
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
Released on Sunday, January 15 2023.
44

5+
- Updated build system to use NUKE instead of CAKE
56
- Dropped .NET Framework 4.6
67
- Updated to use AngleSharp 0.17
78
- Updated micro parser API to be public (#111)

CONTRIBUTORS.md

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ AngleSharp.Css contains code written by (in order of first pull request / commit
1010
* [Tom Hazell](https://github.com/The-Nutty)
1111
* [Michael Ganss](https://github.com/mganss)
1212
* [Gérald Barré](https://github.com/meziantou)
13+
* [Shesh](https://github.com/sheshnathverma)
14+
* [Martin Welsch](https://github.com/MartinWelsch)
15+
* [Jason Nelson](https://github.com/iamcarbon)
16+
* [Bastian Buchholz](https://github.com/campersau)
17+
* [Fraaankes](https://github.com/Fraaankes)
18+
* [Eric Mutta](https://github.com/ericmutta)
1319

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

src/AngleSharp.Css.Tests/CssConstructionFunctions.cs

+14
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,19 @@ internal static Predicate<IRenderDevice> CreateValidator(String name, String val
9696
var feature = new MediaFeature(name, value);
9797
return device => validator.Validate(feature, device);
9898
}
99+
100+
internal static CssFontFeatureValuesRule ParseFontFeatureValuesRule(String source)
101+
{
102+
ICssParser parser = new CssParser();
103+
var sheet = parser.ParseStyleSheet(String.Empty);
104+
return parser.ParseRule(sheet, source) as CssFontFeatureValuesRule;
105+
}
106+
107+
internal static CssCounterStyleRule ParseCounterStyleRule(String source)
108+
{
109+
ICssParser parser = new CssParser();
110+
var sheet = parser.ParseStyleSheet(String.Empty);
111+
return parser.ParseRule(sheet, source) as CssCounterStyleRule;
112+
}
99113
}
100114
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace AngleSharp.Css.Tests.Rules
2+
{
3+
using AngleSharp.Dom;
4+
using NUnit.Framework;
5+
using static CssConstructionFunctions;
6+
7+
[TestFixture]
8+
public class CssCounterStyleRuleTests
9+
{
10+
[Test]
11+
public void CssCounterStyleThumbsIntroExample()
12+
{
13+
var source = "@counter-style thumbs {\n system: cyclic;\n symbols: \"\"\\1F44D\"\";\n suffix: \"\" \"\";\n }";
14+
var rule = ParseCounterStyleRule(source);
15+
Assert.AreEqual("thumbs", rule.StyleName);
16+
}
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace AngleSharp.Css.Tests.Rules
2+
{
3+
using AngleSharp.Dom;
4+
using NUnit.Framework;
5+
using static CssConstructionFunctions;
6+
7+
[TestFixture]
8+
public class CssFontFeatureValuesRuleTests
9+
{
10+
[Test]
11+
public void CssFontFeaturesValuesForSomeIntroExample()
12+
{
13+
var source = "@font-feature-values Font One {\n @styleset {\n nice-style: 12;\n }\n }";
14+
var rule = ParseFontFeatureValuesRule(source);
15+
Assert.AreEqual("Font One", rule.FamilyName);
16+
}
17+
}
18+
}

src/AngleSharp.Css.nuspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<copyright>Copyright 2016-2023, AngleSharp</copyright>
1616
<tags>html html5 css css3 dom styling library anglesharp angle</tags>
1717
<dependencies>
18-
<dependency id="AngleSharp" version="0.17" />
18+
<dependency id="AngleSharp" version="[0.17.0,0.18.0)" />
1919
</dependencies>
2020
</metadata>
2121
</package>

src/AngleSharp.Css/Parser/CssBuilder.cs

+23-4
Original file line numberDiff line numberDiff line change
@@ -324,15 +324,34 @@ private CssSupportsRule CreateSupports(CssSupportsRule rule, CssToken current)
324324

325325
private CssFontFeatureValuesRule CreateFontFeatureValues(CssFontFeatureValuesRule rule, CssToken current)
326326
{
327-
CollectTrivia(ref current);
328-
//rule.FamilyName =
327+
var token = NextToken();
328+
CollectTrivia(ref token);
329+
rule.FamilyName = GetArgument(ref token);
330+
331+
if (token.Type == CssTokenType.CurlyBracketOpen)
332+
{
333+
JumpToRuleEnd(ref token);
334+
return rule;
335+
}
336+
337+
SkipDeclarations(token);
329338
return null;
330339
}
331340

332341
private CssCounterStyleRule CreateCounterStyle(CssCounterStyleRule rule, CssToken current)
333342
{
334-
CollectTrivia(ref current);
335-
return null;
343+
var token = NextToken();
344+
CollectTrivia(ref token);
345+
rule.StyleName = GetArgument(ref token);
346+
347+
if (token.Type != CssTokenType.CurlyBracketOpen)
348+
{
349+
SkipDeclarations(token);
350+
return null;
351+
}
352+
353+
FillDeclarations(rule);
354+
return rule;
336355
}
337356

338357
public CssStyleRule CreateStyle(CssStyleRule rule, CssToken current)

0 commit comments

Comments
 (0)