-
Notifications
You must be signed in to change notification settings - Fork 222
Razor Comments Introduce Carriage Returns #428
Comments
@RehanSaeed The reason why you're seeing the extra carriage returns is due to the newline following the
As for if this is right or not: Currently the only Razor comment we have only consumes the content it surrounds. You're definitely not the first person to bring up such an issue however. Maybe filing an issue to add the ability to provide single line Razor comments (like C#'s |
Adding single line comments sounds nice but that will still mean multi-line comments does not do what most developers expect. I can think of no reason when a developer would want it to add blank lines. The only way to get it to behave as expected is to use your workaround which is pretty ugly. |
@RehanSaeed The Razor comment clearly distinguishes were it starts and where it ends. HTML is white-space sensitive so adding newline consumption to a type of comment that has a start/end would lead to other issues. Take the following examples:
I'd definitely expect to see a newline in each of these examples. You could say that if |
Created a "Create Razor single line comment alternative" issue: #451 |
We've decided to be smart about removing whitespace for any non-HTML content that occupies the entire line. So in addition to @RehanSaeed's example above, the following example: @{
}
<!DOCTYPE html> Should render just the doctype without any leading whitespace (which would be invalid). Also: @foreach (var item in items)
{
<li>@item</li>
} Should not render a line with four spaces before the list item. |
@danroth27 Excellent! Imagine how much wasted bandwidth this change will save over the next decade! |
😄 |
I wrote a blog post about how much bandwidth this feature might have saved the internet here. |
Using Razor comments, can cause extra carriage returns to appear in the generated HTML. This has been a problem in MVC 5 also.
The above code generates the following HTML. You can imagine that with a lot of comments you get a lot of blank lines appearing in your code. If you really wanted a blank line to appear, you could add one yourself before the comment.
Ideally it should generate this HTML:
The text was updated successfully, but these errors were encountered: