};
function compressWhitespace(spaces) {
- return spaces === '\t' ? spaces : ' ';
+ return spaces === '\t' ? '\t' : ~spaces.indexOf('\xA0') ? '\xA0' : ' ';
}
function collapseWhitespaceAll(str) {
- return str ? str.replace(/[\t\n\r ]+/g, compressWhitespace) : str;
+ return str ? str.replace(/\s+/g, compressWhitespace) : str;
}
function collapseWhitespace(str, options, trimLeft, trimRight, collapseAll) {
var lineBreakBefore = '', lineBreakAfter = '';
if (options.preserveLineBreaks) {
- str = str.replace(/^[\t ]*[\n\r][\t\n\r ]*/, function() {
+ str = str.replace(/^\s*?[\n\r]\s*/, function() {
lineBreakBefore = '\n';
return '';
- }).replace(/[\t ]*[\n\r][\t\n\r ]*$/, function() {
+ }).replace(/\s*?[\n\r]\s*$/, function() {
lineBreakAfter = '\n';
return '';
});
input = '<head> <!-- a --> <!-- b --> <!-- c --><link> </head>';
output = '<head><!-- a --><!-- b --><!-- c --><link></head>';
assert.equal(minify(input, { collapseWhitespace: true }), output);
+ input = '<p> foo\u00A0bar\nbaz \u00A0\nmoo\t</p>';
+ output = '<p>foo\u00A0bar baz\u00A0moo</p>';
+ assert.equal(minify(input, { collapseWhitespace: true }), output);
});
QUnit.test('doctype normalization', function(assert) {
collapseWhitespace: true,
conservativeCollapse: true
}), output);
+
+ input = '<p>\u00A0</p>';
+ assert.equal(minify(input, {
+ collapseWhitespace: true,
+ conservativeCollapse: true
+ }), input);
});
QUnit.test('collapse preseving a line break', function(assert) {