Skip to content

Commit

Permalink
Allow disabling of nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl committed Jan 17, 2024
1 parent c39af8a commit bf4db74
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/AngleSharp.Css.Tests/Styling/CssCases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ private static ICssStyleSheet ParseSheet(String text)
{
IsIncludingUnknownDeclarations = true,
IsIncludingUnknownRules = true,
IsExcludingNesting = true,
IsToleratingInvalidSelectors = false,
});
}
Expand Down
12 changes: 6 additions & 6 deletions src/AngleSharp.Css/Extensions/StyleCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ IEnumerable<Tuple<ICssStyleRule, Priority>> MapPriority(ICssStyleRule rule)
if (rule.TryMatch(element, null, out var specificity))
{
yield return Tuple.Create(rule, specificity);
}

foreach (var subRule in rule.Rules)
foreach (var subRule in rule.Rules)
{
if (subRule is ICssStyleRule style)
{
if (subRule is ICssStyleRule style)
foreach (var item in MapPriority(style))
{
foreach (var item in MapPriority(style))
{
yield return item;
}
yield return item;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/AngleSharp.Css/Parser/CssBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ public void CreateDeclarationWith(ICssProperties properties, ref CssToken token)
CollectTrivia(ref token);
var start = token.Position;

if (token.IsPotentiallyNested() && properties is ICssStyleDeclaration decl && decl.Parent is CssStyleRule style)
if (!_options.IsExcludingNesting && token.IsPotentiallyNested() && properties is ICssStyleDeclaration decl && decl.Parent is CssStyleRule style)
{
var rule = new CssStyleRule(style.Owner);
var result = CreateStyle(rule, token);
Expand Down
13 changes: 13 additions & 0 deletions src/AngleSharp.Css/Parser/CssParserOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,18 @@ public Boolean IsToleratingInvalidSelectors
get;
set;
}

/// <summary>
/// Gets or sets if nesting of style rules should be
/// disabled; if disabled the interpretation is closer to
/// older browser also accepting declarations such as
/// "*x-overflow", which would otherwise be an invalid
/// nesting rule.
/// </summary>
public Boolean IsExcludingNesting
{
get;
set;
}
}
}

0 comments on commit bf4db74

Please sign in to comment.