Skip to content

Commit

Permalink
Also use it for pages
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl committed Jan 6, 2022
1 parent 8b8482a commit f85b2f6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
29 changes: 29 additions & 0 deletions src/AngleSharp.Css/Dom/Internal/Rules/CssPageRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public String SelectorText

#region Methods

internal void SetInvalidSelector(String selectorText)
{
_selector = new InvalidSelector(selectorText);
}

protected override void ReplaceWith(ICssRule rule)
{
var newRule = (ICssPageRule)rule;
Expand All @@ -59,5 +64,29 @@ public override void ToCss(TextWriter writer, IStyleFormatter formatter)
}

#endregion

#region Selector

class InvalidSelector : ISelector
{
private readonly String _text;

public InvalidSelector(String text)
{
_text = text;
}

public String Text => _text;

public Priority Specificity => Priority.Zero;

public void Accept(ISelectorVisitor visitor)
{
}

public Boolean Match(IElement element, IElement scope) => false;
}

#endregion
}
}
10 changes: 9 additions & 1 deletion src/AngleSharp.Css/Parser/CssBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,15 @@ private CssNamespaceRule CreateNamespace(CssNamespaceRule rule, CssToken current
private CssPageRule CreatePage(CssPageRule rule, CssToken current)
{
current = NextToken();
rule.SelectorText = GetArgument(ref current);
var selectorText = GetArgument(ref current);

rule.SelectorText = selectorText;

if (rule.Selector is null && _options.IsToleratingInvalidSelectors)
{
rule.SetInvalidSelector(selectorText);
}

CollectTrivia(ref current);

if (current.Type != CssTokenType.CurlyBracketOpen)
Expand Down

0 comments on commit f85b2f6

Please sign in to comment.