Skip to content

Commit

Permalink
Merge pull request #1 from GCAE/work/nested-minify
Browse files Browse the repository at this point in the history
Remove spaces when minifying new lines not in inline elements
  • Loading branch information
erdomke authored Oct 20, 2019
2 parents 07cc3a5 + d5e60cc commit cba73e5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/BracketPipe.Tests/MinificationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ public void Minify_DontAlterWbr()
Assert.Equal(input, Html.Minify(input));
}


[Fact]
public void Minify_DontConcatenateScriptTags()
{
Expand All @@ -188,5 +187,13 @@ public void Minify_MinifyScriptTags()
settings.ScriptTypesToCompress.Clear();
Assert.Equal(input, Html.Minify(input, settings));
}

[Fact]
public void Minify_NoSpaceBetweenNestedElements()
{
Assert.Equal("<div>Foo</div><div></div>",
Html.Minify(@"<div>Foo</div>
<div></div>"));
}
}
}
7 changes: 6 additions & 1 deletion src/BracketPipe/Html.Minify.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,12 @@ public static IEnumerable<HtmlNode> Minify(this IEnumerable<HtmlNode> reader, Ht
}
else
{
yield return new HtmlText(node.Position, " ");
// Inline elements can render spaces, otherwise spaces shouldn't be rendered between elements
if ((node.Type == HtmlTokenType.StartTag || node.Type == HtmlTokenType.EndTag)
&& settings.InlineElements.Contains(node.Value))
{
yield return new HtmlText(node.Position, " ");
}
if (settings.PreserveSurroundingSpaceTags.Contains(node.Value))
state = MinifyState.Compressed;
else
Expand Down

0 comments on commit cba73e5

Please sign in to comment.