Skip to content

Commit bf4db74

Browse files
committed
Allow disabling of nesting
1 parent c39af8a commit bf4db74

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

src/AngleSharp.Css.Tests/Styling/CssCases.cs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ private static ICssStyleSheet ParseSheet(String text)
1515
{
1616
IsIncludingUnknownDeclarations = true,
1717
IsIncludingUnknownRules = true,
18+
IsExcludingNesting = true,
1819
IsToleratingInvalidSelectors = false,
1920
});
2021
}

src/AngleSharp.Css/Extensions/StyleCollectionExtensions.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,15 @@ IEnumerable<Tuple<ICssStyleRule, Priority>> MapPriority(ICssStyleRule rule)
116116
if (rule.TryMatch(element, null, out var specificity))
117117
{
118118
yield return Tuple.Create(rule, specificity);
119+
}
119120

120-
foreach (var subRule in rule.Rules)
121+
foreach (var subRule in rule.Rules)
122+
{
123+
if (subRule is ICssStyleRule style)
121124
{
122-
if (subRule is ICssStyleRule style)
125+
foreach (var item in MapPriority(style))
123126
{
124-
foreach (var item in MapPriority(style))
125-
{
126-
yield return item;
127-
}
127+
yield return item;
128128
}
129129
}
130130
}

src/AngleSharp.Css/Parser/CssBuilder.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ public void CreateDeclarationWith(ICssProperties properties, ref CssToken token)
524524
CollectTrivia(ref token);
525525
var start = token.Position;
526526

527-
if (token.IsPotentiallyNested() && properties is ICssStyleDeclaration decl && decl.Parent is CssStyleRule style)
527+
if (!_options.IsExcludingNesting && token.IsPotentiallyNested() && properties is ICssStyleDeclaration decl && decl.Parent is CssStyleRule style)
528528
{
529529
var rule = new CssStyleRule(style.Owner);
530530
var result = CreateStyle(rule, token);

src/AngleSharp.Css/Parser/CssParserOptions.cs

+13
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,18 @@ public Boolean IsToleratingInvalidSelectors
3636
get;
3737
set;
3838
}
39+
40+
/// <summary>
41+
/// Gets or sets if nesting of style rules should be
42+
/// disabled; if disabled the interpretation is closer to
43+
/// older browser also accepting declarations such as
44+
/// "*x-overflow", which would otherwise be an invalid
45+
/// nesting rule.
46+
/// </summary>
47+
public Boolean IsExcludingNesting
48+
{
49+
get;
50+
set;
51+
}
3952
}
4053
}

0 commit comments

Comments
 (0)