Closed walterDurin closed 7 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.
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.
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);
Can anyone attach a sample file to reproduce the error? Then we can add that file to the UnitTests...
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.
Thanks @Deutschi what would be the correct output on those examples?
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.
This issue should be fixed with the latest release!
@deanhume I don't think this has been fixed yet...
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) { @:
}