deanhume / html-minifier

A simple command line tool to minify your HTML, Razor views & Web Forms views
http://deanhume.github.io/html-minifier/
MIT License
134 stars 86 forks source link

Razor @: error still broken after v1.7 #24

Closed walterDurin closed 7 years ago

walterDurin commented 8 years ago

I hate to be a thorn in anyone's side but v1.7 did not fix this issue, razor "@:" need to be on its own line or it breaks, it is still broken in 1.7, I don't know why it was closed as fixed when it is not.

test:

@if (true) { @:

}

0xApp commented 8 years ago

@walterDurin consider using

@if (true){
    <text> you content here,
         some more content here
    </text>
}

The tag is an element that is treated specially by Razor. It causes Razor to interpret the inner contents of the block as content, and to not render the containing tag element (meaning only the inner contents of the element will be rendered – the tag itself will not). This makes it convenient when you want to render multi-line content blocks that are not wrapped by an HTML element.

Check this

ConcatenatedNonsense commented 8 years ago

Just tried the Minifier on the release code version of an existing project and the site errored outright on load.

Event Viewer shows that it failed at the first @if statement inside the minified code.

heldersepu commented 7 years ago

Look here: https://github.com/deanhume/html-minifier/blob/master/ViewMinifier/StreamReaderExtension.cs#L54 I believe all we need to do is add a line: declarations.Add("@if ", false);

heldersepu commented 7 years ago

Can anyone attach a sample file to reproduce the error? Then we can add that file to the UnitTests...

Deutschi commented 7 years ago

Example 1:

Input:

<div>
    @if (true)
    {
        @: this is normal text without html tag
    }
</div>

Output:

<div> @if (true) { @: this is normal text without html tag } </div>

The closing "}" is no longer recognized as syntax, because it's on the same line as the "@:"

Example 2:

Input:

<div>
    @switch (foo)
    {
        default:
            @: @Model.Name
            break;
    }
</div>

Output:

<div> @switch (foo) { default: @: @Model.Name break; } </div>

The "break" is no longer recognized as syntax, same as example 1.

heldersepu commented 7 years ago

Thanks @Deutschi what would be the correct output on those examples?

Deutschi commented 7 years ago

Valid output:

<div> @if (true) { @: this is normal text without html tag
} </div>
<div> @switch (foo) { default: @: @Model.Name
break; } </div>

Suggestion: The next line break after an "@:" should not be replaced.

deanhume commented 7 years ago

This issue should be fixed with the latest release!

heldersepu commented 7 years ago

@deanhume I don't think this has been fixed yet...