Skip to content

Commit

Permalink
Merge pull request #157 from lee-m/page-rules-issues
Browse files Browse the repository at this point in the history
@page rule parsing fixes
  • Loading branch information
TylerBrinks authored Jul 6, 2023
2 parents e818a49 + 86e6b73 commit c85b2cb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/ExCSS.Tests/Cases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,5 +1081,16 @@ public void StylesheetIncludeUnknownDeclarationsWithKnownPropertyShouldNotUseUnk

Assert.IsNotType<UnknownProperty>(((StyleRule)document.Rules[0]).Style.Children.First());
}

[Theory]
[InlineData("@page { margin-bottom: 5pt; margin-top: 5pt }", "@page {margin-bottom: 5pt; margin-top: 5pt; }")]
[InlineData("@page :left { margin-bottom: 5pt; margin-top: 5pt }", "@page :left {margin-bottom: 5pt; margin-top: 5pt; }")]
public void PageRuleCSSOutput(string input, string expected)
{
var parser = new StylesheetParser();
var document = parser.Parse(input);

Assert.Equal(expected, document.ToCss());
}
}
}
4 changes: 3 additions & 1 deletion src/ExCSS/Parser/StylesheetComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ public Rule CreatePage(Token current)
// e.g. @page :left{...}
rule.Selector = CreatePageSelector(ref token);
ParseComments(ref token);
token = NextToken();
}

if (token.Type == TokenType.CurlyBracketOpen)
Expand Down Expand Up @@ -478,6 +477,9 @@ private PageSelector CreatePageSelector(ref Token token)
// Add the pseudo class selector
token = NextToken();
selector = token.Type == TokenType.Ident ? new PageSelector(token.Data) : new PageSelector();

//Skip past the pseudo class identifier
token = NextToken();
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/ExCSS/Rules/PageRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal PageRule(StylesheetParser parser)

public override void ToCss(TextWriter writer, IStyleFormatter formatter)
{
writer.Write(formatter.Rule("@page", SelectorText, "{"));
writer.Write(formatter.Rule("@page", Selector == null ? "" : SelectorText, "{"));

Style.ToCss(writer, formatter);

Expand Down

0 comments on commit c85b2cb

Please sign in to comment.