Skip to content

Commit bd83c45

Browse files
committed
Made parser API public #111
1 parent fc0ad92 commit bd83c45

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+576
-97
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ Released on Tuesday, May 31 2022.
44

55
- Dropped .NET Framework 4.6
66
- Updated to use AngleSharp 0.17
7+
- Updated micro parser API to be public (#111)
78
- Fixed casing issue with color, timing, and gradient functions (#109)
89
- Fixed parsing of `skew` (#101)
910
- Fixed shorthand properties using `inherit` being omitted (#100)
11+
- Added support for `@counter-style` (#102)
12+
- Added support for `@font-feature-values` (#102)
1013
- Added support for `conic-gradient` (#101)
1114

1215
# 0.16.4

src/AngleSharp.Css/Constants/RuleNames.cs

+10
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,15 @@ public static class RuleNames
5656
/// The @page rule.
5757
/// </summary>
5858
public static readonly String Page = "@page";
59+
60+
/// <summary>
61+
/// The @counter-style rule.
62+
/// </summary>
63+
public static readonly String CounterStyle = "@counter-style";
64+
65+
/// <summary>
66+
/// The @font-feature-values rule.
67+
/// </summary>
68+
public static readonly String FontFeatureValues = "@font-feature-values";
5969
}
6070
}

src/AngleSharp.Css/Dom/CssRuleType.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace AngleSharp.Css.Dom
1+
namespace AngleSharp.Css.Dom
22
{
33
using AngleSharp.Attributes;
44

@@ -7,7 +7,7 @@
77
/// </summary>
88
[DomName("CSSRule")]
99
public enum CssRuleType : byte
10-
{
10+
{
1111
/// <summary>
1212
/// The rule is not known and cannot be used.
1313
/// </summary>
@@ -86,6 +86,6 @@ public enum CssRuleType : byte
8686
/// Creating a CSS region with @region.
8787
/// </summary>
8888
[DomName("REGION_STYLE_RULE")]
89-
RegionStyle = 16
89+
RegionStyle = 16,
9090
}
9191
}

src/AngleSharp.Css/Dom/Internal/CssMedium.cs

+34-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace AngleSharp.Css.Dom
1010
/// Represents a medium rule. More information available at:
1111
/// http://www.w3.org/TR/css3-mediaqueries/
1212
/// </summary>
13-
sealed class CssMedium : ICssMedium
13+
public sealed class CssMedium : ICssMedium
1414
{
1515
#region Fields
1616

@@ -23,11 +23,24 @@ sealed class CssMedium : ICssMedium
2323

2424
#region ctor
2525

26+
/// <summary>
27+
/// Creates a new CSS medium.
28+
/// </summary>
29+
/// <param name="type">The type of the media rule.</param>
30+
/// <param name="inverse">Specifies if it should be inverted.</param>
31+
/// <param name="exclusive">Specifies if the rule is exclusive.</param>
2632
public CssMedium(String type, Boolean inverse, Boolean exclusive)
2733
: this(type, inverse, exclusive, Enumerable.Empty<IMediaFeature>())
2834
{
2935
}
3036

37+
/// <summary>
38+
/// Creates a new CSS medium.
39+
/// </summary>
40+
/// <param name="type">The type of the media rule.</param>
41+
/// <param name="inverse">Specifies if it should be inverted.</param>
42+
/// <param name="exclusive">Specifies if the rule is exclusive.</param>
43+
/// <param name="features">The features of the medium.</param>
3144
public CssMedium(String type, Boolean inverse, Boolean exclusive, IEnumerable<IMediaFeature> features)
3245
{
3346
_features = new List<IMediaFeature>(features);
@@ -40,20 +53,36 @@ public CssMedium(String type, Boolean inverse, Boolean exclusive, IEnumerable<IM
4053

4154
#region Properties
4255

56+
/// <summary>
57+
/// Gets the feature demands (constraints) of the medium.
58+
/// </summary>
4359
public IEnumerable<IMediaFeature> Features => _features;
4460

61+
/// <summary>
62+
/// Gets the type of the medium.
63+
/// </summary>
4564
public String Type => _type;
4665

66+
/// <summary>
67+
/// Gets if the medium is exclusive to other media.
68+
/// </summary>
4769
public Boolean IsExclusive => _exclusive;
4870

71+
/// <summary>
72+
/// Gets if the medium should be inverted.
73+
/// </summary>
4974
public Boolean IsInverse => _inverse;
5075

76+
/// <summary>
77+
/// Gets the constraints - i.e., the stringified features.
78+
/// </summary>
5179
public String Constraints => String.Join(" and ", Features.Select(m => m.ToCss()));
5280

5381
#endregion
5482

5583
#region Methods
5684

85+
/// <inheritdoc />
5786
public override Boolean Equals(Object obj)
5887
{
5988
var other = obj as CssMedium;
@@ -80,8 +109,12 @@ public override Boolean Equals(Object obj)
80109
return false;
81110
}
82111

112+
/// <inheritdoc />
83113
public override Int32 GetHashCode() => base.GetHashCode();
84114

115+
/// <summary>
116+
/// Writes the medium as CSS.
117+
/// </summary>
85118
public void ToCss(TextWriter writer, IStyleFormatter formatter)
86119
{
87120
var offset = 0;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
namespace AngleSharp.Css.Dom
2+
{
3+
using AngleSharp.Css;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Diagnostics;
7+
8+
/// <summary>
9+
/// Represents the @counter-style rule.
10+
/// </summary>
11+
[DebuggerDisplay(null, Name = "CssCounterStyleRule ({StyleName})")]
12+
sealed class CssCounterStyleRule : CssDeclarationRule, ICssRule
13+
{
14+
#region ctor
15+
16+
internal CssCounterStyleRule(ICssStyleSheet owner)
17+
: base(owner, CssRuleType.CounterStyle, RuleNames.CounterStyle, new HashSet<String>())
18+
{
19+
}
20+
21+
#endregion
22+
23+
#region Properties
24+
25+
/// <summary>
26+
/// Gets or sets the counter style name argument.
27+
/// </summary>
28+
public String StyleName { get; set; }
29+
30+
#endregion
31+
32+
#region Methods
33+
34+
protected override void ReplaceWith(ICssRule rule)
35+
{
36+
}
37+
38+
#endregion
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
namespace AngleSharp.Css.Dom
2+
{
3+
using AngleSharp.Css;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Diagnostics;
7+
8+
/// <summary>
9+
/// Represents the @font-feature-values rule.
10+
/// </summary>
11+
[DebuggerDisplay(null, Name = "CssFontFeatureValuesRule ({FamilyName})")]
12+
sealed class CssFontFeatureValuesRule : CssDeclarationRule, ICssRule
13+
{
14+
#region ctor
15+
16+
internal CssFontFeatureValuesRule(ICssStyleSheet owner)
17+
: base(owner, CssRuleType.FontFeatureValues, RuleNames.FontFeatureValues, new HashSet<String>())
18+
{
19+
// character-variant, styleset, stylistic, ornaments, annotation, swash
20+
}
21+
22+
#endregion
23+
24+
#region Properties
25+
26+
/// <summary>
27+
/// Gets or sets the family name argument.
28+
/// </summary>
29+
public String FamilyName { get; set; }
30+
31+
#endregion
32+
33+
#region Methods
34+
35+
protected override void ReplaceWith(ICssRule rule)
36+
{
37+
}
38+
39+
#endregion
40+
}
41+
}

src/AngleSharp.Css/Parser/CssBuilder.cs

+25-2
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@ private ICssRule CreateAtRule(ICssStyleSheet sheet, CssToken token)
116116
var rule = new CssDocumentRule(sheet);
117117
return CreateDocument(rule, token);
118118
}
119+
else if (token.Data.Is(RuleNames.CounterStyle))
120+
{
121+
var rule = new CssCounterStyleRule(sheet);
122+
return CreateCounterStyle(rule, token);
123+
}
124+
else if (token.Data.Is(RuleNames.FontFeatureValues))
125+
{
126+
var rule = new CssFontFeatureValuesRule(sheet);
127+
return CreateFontFeatureValues(rule, token);
128+
}
119129
else if (_options.IsIncludingUnknownRules)
120130
{
121131
return CreateUnknownAtRule(sheet, token);
@@ -279,7 +289,7 @@ private CssPageRule CreatePage(CssPageRule rule, CssToken current)
279289
{
280290
rule.SetInvalidSelector(selectorText);
281291
}
282-
292+
283293
CollectTrivia(ref current);
284294

285295
if (current.Type != CssTokenType.CurlyBracketOpen)
@@ -312,6 +322,19 @@ private CssSupportsRule CreateSupports(CssSupportsRule rule, CssToken current)
312322
return null;
313323
}
314324

325+
private CssFontFeatureValuesRule CreateFontFeatureValues(CssFontFeatureValuesRule rule, CssToken current)
326+
{
327+
CollectTrivia(ref current);
328+
//rule.FamilyName =
329+
return null;
330+
}
331+
332+
private CssCounterStyleRule CreateCounterStyle(CssCounterStyleRule rule, CssToken current)
333+
{
334+
CollectTrivia(ref current);
335+
return null;
336+
}
337+
315338
public CssStyleRule CreateStyle(CssStyleRule rule, CssToken current)
316339
{
317340
CollectTrivia(ref current);
@@ -556,7 +579,7 @@ private void JumpToRuleEnd(ref CssToken current)
556579
{
557580
scopes--;
558581
}
559-
582+
560583
if (scopes <= 0 && (current.Is(CssTokenType.CurlyBracketClose, CssTokenType.Semicolon)))
561584
{
562585
break;

src/AngleSharp.Css/Parser/Micro/CalcParser.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ namespace AngleSharp.Css.Parser
66
using System;
77
using System.Globalization;
88

9-
static class CalcParser
9+
/// <summary>
10+
/// Represents extensions to for calc values.
11+
/// </summary>
12+
public static class CalcParser
1013
{
14+
/// <summary>
15+
/// Parses a calc value, if any.
16+
/// </summary>
1117
public static CssCalcValue ParseCalc(this StringSource source)
1218
{
1319
var pos = source.Index;

src/AngleSharp.Css/Parser/Micro/ColorParser.cs

+9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ namespace AngleSharp.Css.Parser
66
using System.Collections.Generic;
77
using System.Globalization;
88

9+
/// <summary>
10+
/// Represents extensions to for color values.
11+
/// </summary>
912
static class ColorParser
1013
{
1114
private static readonly Dictionary<String, Func<StringSource, Color?>> ColorFunctions = new Dictionary<String, Func<StringSource, Color?>>(StringComparer.OrdinalIgnoreCase)
@@ -19,6 +22,9 @@ static class ColorParser
1922
{ FunctionNames.Hwba, ParseHwba },
2023
};
2124

25+
/// <summary>
26+
/// Parses a color value, if any.
27+
/// </summary>
2228
public static Color? ParseColor(this StringSource source)
2329
{
2430
var pos = source.Index;
@@ -32,6 +38,9 @@ static class ColorParser
3238
return result;
3339
}
3440

41+
/// <summary>
42+
/// Parses a the current color value, if any.
43+
/// </summary>
3544
public static Color? ParseCurrentColor(this StringSource source) =>
3645
source.IsIdentifier(CssKeywords.CurrentColor) ? Color.CurrentColor : ColorParser.ParseColor(source);
3746

src/AngleSharp.Css/Parser/Micro/CompoundParser.cs

+19-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ namespace AngleSharp.Css.Parser
66
using System;
77
using System.Collections.Generic;
88

9-
static class CompoundParser
9+
/// <summary>
10+
/// Represents extensions to for general CSS compount values.
11+
/// </summary>
12+
public static class CompoundParser
1013
{
14+
/// <summary>
15+
/// Parse for a CSS quote value.
16+
/// </summary>
1117
public static CssTupleValue ParseQuotes(this StringSource source)
1218
{
1319
var quotes = new List<ICssValue>();
@@ -30,6 +36,9 @@ public static CssTupleValue ParseQuotes(this StringSource source)
3036
return new CssTupleValue(quotes.ToArray());
3137
}
3238

39+
/// <summary>
40+
/// Parse for a CSS border image slice.
41+
/// </summary>
3342
public static CssBorderImageSliceValue ParseBorderImageSlice(this StringSource source)
3443
{
3544
var lengths = new Length[4];
@@ -73,6 +82,9 @@ public static CssBorderImageSliceValue ParseBorderImageSlice(this StringSource s
7382
return null;
7483
}
7584

85+
/// <summary>
86+
/// Parse for a CSS background repeat.
87+
/// </summary>
7688
public static CssImageRepeatsValue ParseBackgroundRepeat(this StringSource source)
7789
{
7890
if (source.IsIdentifier(CssKeywords.RepeatX))
@@ -106,6 +118,9 @@ public static CssImageRepeatsValue ParseBackgroundRepeat(this StringSource sourc
106118
return null;
107119
}
108120

121+
/// <summary>
122+
/// Parse for a CSS image source.
123+
/// </summary>
109124
public static ICssImageValue ParseImageSource(this StringSource source)
110125
{
111126
var url = source.ParseUri();
@@ -118,6 +133,9 @@ public static ICssImageValue ParseImageSource(this StringSource source)
118133
return url;
119134
}
120135

136+
/// <summary>
137+
/// Parse for a generic periodic [u, y, d, x] value.
138+
/// </summary>
121139
public static CssPeriodicValue<T> ParsePeriodic<T>(this StringSource source, Func<StringSource, T> converter)
122140
where T : ICssValue
123141
{

0 commit comments

Comments
 (0)