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

Suppress leading/trailing whitespace from emitted markup #10415

Open
lonix1 opened this issue May 27, 2024 · 2 comments
Open

Suppress leading/trailing whitespace from emitted markup #10415

lonix1 opened this issue May 27, 2024 · 2 comments
Labels
area-compiler Umbrella for all compiler issues untriaged

Comments

@lonix1
Copy link

lonix1 commented May 27, 2024

If a method returning markup contains whitespace, it will not be minified / trimmed. That makes the UI ugly, and we need to remember to format it to suppress the whitespace.

But the problem is created by the razor compiler, so the real fix is there. Instead of css hacks, one can do this:

  public void Foo() {@*
  *@<div>
      <p>Hello</p>
    </div>@*
*@}

That is also a hack, and is really ugly, but it works - no leading/trailing whitespace will be emitted. And that is the correct location for the solution. (Also one does not need to remember to add css hacks later.)

But that leads to another problem: that method looks weird when collapsed and makes the document hard to read. For the above example, without the hack, it correctly collapses to:

  public void Foo() {...

But with the hack:

  public void Foo() {@*
  *@<div>
    </div>@*
*@}

I think there are two solutions:

  • make it so the collapsed method looks good despite the interspersed @* and *@
  • or better, trim whitespace from the emitted markup
@davidwengier davidwengier added the area-compiler Umbrella for all compiler issues label May 27, 2024
@jjonescz
Copy link
Contributor

  • make it so the collapsed method looks good despite the interspersed @* and *@

Can you elaborate? Collapsing seems to work fine for me in Visual Studio:

Expanded Collapsed
image image
  • or better, trim whitespace from the emitted markup

That would be a breaking change in the compiler.

@lonix1
Copy link
Author

lonix1 commented May 28, 2024

Thanks.

Collapsing seems to work fine for me in Visual Studio

I'm using VSCode maybe that's why it looks different for me. Also I'm using RazorPages rather than Blazor, so it looks weird for me in @functions { } and @{ } blocks.

That would be a breaking change in the compiler.

That's unfortunate. I wonder whether there's some way to do that without introducing a breaking change (maybe a compile flag or pragma or directive or something).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-compiler Umbrella for all compiler issues untriaged
Projects
None yet
Development

No branches or pull requests

3 participants