Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix formatting of escaped at signs #11462

Merged
merged 1 commit into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have purposely bad formatting here to demonstrate our formatter ignores it in this case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our test infra doesn't know how to format CSS or TypeScript, so it's all "bad formatting" as far as the C# formatter is concerned.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, my suggestion was to have bad formatting in input an output (extra or missing space, bad indentation) so it's obvious we are not trying to format in that case. No big deal.

</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 />
}
""");
}
}