Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

Remove unnecessary whitespace that is rendered for non markup content #485

Closed
ajaybhargavb opened this issue Aug 13, 2015 · 6 comments
Closed
Assignees
Milestone

Comments

@ajaybhargavb
Copy link
Contributor

Extra new lines from razor comments has been removed in #428. But we still need to handle unnecessary whitespace in other places.

From @danroth27:
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 #428 (comment), 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.

cc' @NTaylorMullen

@Eilon Eilon added this to the 4.0.0-beta8 milestone Aug 14, 2015
@RehanSaeed
Copy link

@ajaybhargavb Please also consider this (#423) related suggestion for minifying HTML at compile time.

ajaybhargavb added a commit that referenced this issue Sep 10, 2015
- #485
- Using a flag to consume whitespace and newline at the end of a verbatim block
- Added tests to validate nested blocks
ajaybhargavb added a commit that referenced this issue Sep 10, 2015
- #485
- Using a flag to consume whitespace and newline at the end of a verbatim block
- Added tests to validate nested blocks
@ajaybhargavb
Copy link
Contributor Author

e2881b0

ajaybhargavb added a commit to aspnet/Mvc that referenced this issue Sep 11, 2015
ajaybhargavb added a commit to aspnet/Mvc that referenced this issue Sep 11, 2015
@NickAb
Copy link

NickAb commented Apr 26, 2016

In ASP.NET Core project in my .cshtml when I use

Some text
@if (Model.BranchesSection.TotalCount == Model.BranchesSection.PreviousIssuedBranchesCount)
                    {
                        <text> same as before</text>
                    }.

I get following as a result:

Some text same as before .

There is a space before full stop symbol. How can I get rid of it? Is my only option to inline it like so:

Some text @if (Model.BranchesSection.TotalCount == Model.BranchesSection.PreviousIssuedBranchesCount) { <text> same as before</text> }.

@NTaylorMullen
Copy link
Member

@NickAb I was able to reproduce your issue with:

Some text
@if (true)
{
    <text> same as before</text>
}.

And even

@if (true)
{
    @: same as before
}.

Would you mind opening a separate issue with what you have?

Also, as a work around this works (still ugly 😢 ):

Some text
@if (true)
{
    <text> same as before</text>}.

@NTaylorMullen
Copy link
Member

Actually, nm @NickAb this issue should be reopened. The browser was being kind rendering a space, the HTML is actually a newline which should have been covered by this issue.

@ajaybhargavb
Copy link
Contributor Author

b520c9c

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants