From: GoalSmashers Date: Sat, 30 Mar 2013 11:44:08 +0000 (+0100) Subject: Follow up to #86 - removing extra line break when cleaning up extra comments. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=f344e74f72b7ba4a76d3ed1550c93079a94405b3;p=clean-css.git Follow up to #86 - removing extra line break when cleaning up extra comments. --- diff --git a/lib/clean.js b/lib/clean.js index 3779351c..c40642fd 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -321,13 +321,14 @@ var CleanCSS = { }); var specialCommentsCount = context.specialComments.length; - replace(/__CSSCOMMENT__/g, function() { + var breakSuffix = options.keepBreaks ? lineBreak : ''; + replace(new RegExp('__CSSCOMMENT__(' + lineBreak + ')?', 'g'), function() { switch (options.keepSpecialComments) { case '*': - return context.specialComments.shift(); + return context.specialComments.shift() + breakSuffix; case 1: return context.specialComments.length == specialCommentsCount ? - context.specialComments.shift() : + context.specialComments.shift() + breakSuffix : ''; case 0: return ''; diff --git a/test/unit-test.js b/test/unit-test.js index 1b2d7f6e..6de079d6 100644 --- a/test/unit-test.js +++ b/test/unit-test.js @@ -165,6 +165,12 @@ vows.describe('clean-units').addBatch({ "@charset 'utf-8';" + lineBreak + "a{}" ] }, { keepBreaks: true }), + 'line breaks and important comments': cssContext({ + 'charset to beginning with comment removal': [ + "/*! some comment */" + lineBreak + lineBreak + "@charset 'utf-8';" + lineBreak + lineBreak + "a{}", + "@charset 'utf-8';" + lineBreak + "a{}" + ] + }, { keepBreaks: true, keepSpecialComments: 0 }), 'selectors': cssContext({ 'remove spaces around selectors': [ 'div + span > em',