Skip to content

Commit

Permalink
Fix formatting of escaped at signs
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwengier committed Feb 6, 2025
1 parent f5aebdd commit 9ea83b3
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,18 @@ public override LineInfo VisitRazorMetaCode(RazorMetaCodeSyntax node)
return EmitCurrentLineAsCSharp();
}

public override LineInfo VisitMarkupEphemeralTextLiteral(MarkupEphemeralTextLiteralSyntax node)
{
// A MarkupEphemeralTextLiteral is an escaped @ sign, eg in CSS "@@font-face". We just treat it like markup text
return VisitMarkupLiteral();
}

public override LineInfo VisitMarkupTextLiteral(MarkupTextLiteralSyntax node)
{
return VisitMarkupLiteral();
}

private LineInfo VisitMarkupLiteral()
{
// For markup text literal, we always want to honour the Html formatter, so we supply the Html indent.
// Normally that would only happen if we were inside a markup element
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5854,4 +5854,56 @@ void Foo() { }
@Foo.ToString(1)
""");
}

[FormattingTestFact]
public async Task EscapedAtSignsInCSS()
{
await RunFormattingTestAsync(
input: """
@page "/"
@model IndexModel
<style>
@@media only screen and (max-width: 600px) {
body {
background-color: lightblue;
}
}
</style>
<style>
@@font-face {
src: url();
}
</style>
@if (RendererInfo.IsInteractive)
{
<button />
}
""",
expected: """
@page "/"
@model IndexModel
<style>
@@media only screen and (max-width: 600px) {
body {
background-color: lightblue;
}
}
</style>
<style>
@@font-face {
src: url();
}
</style>
@if (RendererInfo.IsInteractive)
{
<button />
}
""");
}
}

0 comments on commit 9ea83b3

Please sign in to comment.