Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/htmlminifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,9 @@ function minify(value, options, partialMarkup) {
}
var token = uidAttr + ignoredCustomMarkupChunks.length;
ignoredCustomMarkupChunks.push(match);
return '\t' + token + '\t';
var prefix = /^\s*\n/.test(match) ? '\n' : '\t';
var postfix = /\n\s*$/.test(match) ? '\n' : '\t';
return prefix + token + postfix;
});
}

Expand Down
7 changes: 7 additions & 0 deletions tests/minifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -1633,6 +1633,13 @@ QUnit.test('Ignore custom fragments', function(assert) {
ignoreCustomFragments: reFragments
}), output);

input = '<script>//\r\n<% ... %></script>';
output = '<script>\r\n<% ... %></script>';
assert.equal(minify(input, {
minifyJS: true,
ignoreCustomFragments: reFragments,
}), output);

input = '{{ if foo? }}\r\n <div class="bar">\r\n ...\r\n </div>\r\n{{ end \n}}';
output = '{{ if foo? }}<div class="bar">...</div>{{ end }}';
assert.equal(minify(input, {}), input);
Expand Down