It's off by default.
Kudos to @elcodedocle for inspiration.
* Fixed issue [#487](https://github.com/jakubpawlowicz/clean-css/issues/487) - source map paths under Windows.
* Fixed issue [#490](https://github.com/jakubpawlowicz/clean-css/issues/490) - vendor prefixed multivalue `background`.
* Fixed issue [#500](https://github.com/jakubpawlowicz/clean-css/issues/500) - merging duplicate adjacent properties.
+* Fixed issue [#504](https://github.com/jakubpawlowicz/clean-css/issues/504) - keeping `url()` quotes.
* Fixed issue [#507](https://github.com/jakubpawlowicz/clean-css/issues/507) - merging longhands into many shorthands.
* Fixed issue [#508](https://github.com/jakubpawlowicz/clean-css/issues/508) - removing duplicate media queries.
* Fixed issue [#521](https://github.com/jakubpawlowicz/clean-css/issues/521) - unit optimizations inside `calc()`.
* `'[+-]properties.backgroundSizeMerging'` - turn on / off background-size merging into shorthand
* `'[+-]properties.merging'` - turn on / off property merging based on understandability
* `'[+-]properties.spaceAfterClosingBrace'` - turn on / off removing space after closing brace - `url() no-repeat` into `url()no-repeat`
+* `'[+-]properties.urlQuotes'` - turn on / off `url()` quoting
* `'[+-]properties.zeroUnits'` - turn on / off units removal after a `0` value
* `'[+-]selectors.adjacentSpace'` - turn on / off extra space before `nav` element
* `'[+-]selectors.ie7Hack'` - turn on / off IE7 selector hack removal (`*+html...`)
var commentsProcessor = new CommentsProcessor(context, options.keepSpecialComments, options.keepBreaks, options.sourceMap);
var expressionsProcessor = new ExpressionsProcessor(options.sourceMap);
var freeTextProcessor = new FreeTextProcessor(options.sourceMap);
- var urlsProcessor = new UrlsProcessor(context, options.sourceMap);
+ var urlsProcessor = new UrlsProcessor(context, options.sourceMap, options.compatibility.properties.urlQuotes);
var urlRebase = new UrlRebase(context);
var selectorsOptimizer = new SelectorsOptimizer(options, context);
var lineBreak = require('os').EOL;
-function UrlsProcessor(context, saveWaypoints) {
+function UrlsProcessor(context, saveWaypoints, keepUrlQuotes) {
this.urls = new EscapeStore('URL');
this.context = context;
this.saveWaypoints = saveWaypoints;
+ this.keepUrlQuotes = keepUrlQuotes;
}
// Strip urls by replacing them by a special
});
};
-function normalize(url) {
+function normalize(url, keepUrlQuotes) {
url = url
.replace(/^url/gi, 'url')
.replace(/\\?\n|\\?\r\n/g, '')
.replace(/^url\((['"])? /, 'url($1')
.replace(/ (['"])?\)$/, '$1)');
- if (!/url\(.*[\s\(\)].*\)/.test(url) && !/url\(['"]data:[^;]+;charset/.test(url))
+ if (!keepUrlQuotes && !/url\(.*[\s\(\)].*\)/.test(url) && !/url\(['"]data:[^;]+;charset/.test(url))
url = url.replace(/["']/g, '');
return url;
break;
tempData.push(data.substring(cursor, nextMatch.start));
- var url = normalize(this.urls.restore(nextMatch.match));
+ var url = normalize(this.urls.restore(nextMatch.match), this.keepUrlQuotes);
tempData.push(url);
cursor = nextMatch.end;
ieSuffixHack: false, // \9 suffix hacks on IE
merging: true, // merging properties into one
spaceAfterClosingBrace: false, // 'url() no-repeat' to 'url()no-repeat'
+ urlQuotes: false, // whether to wrap content of `url()` into quotes or not
zeroUnits: true // 0[unit] -> 0
},
selectors: {
ieSuffixHack: true,
merging: false,
spaceAfterClosingBrace: true,
+ urlQuotes: false,
zeroUnits: true
},
selectors: {
ieSuffixHack: true,
merging: false,
spaceAfterClosingBrace: true,
+ urlQuotes: false,
zeroUnits: true
},
selectors: {
'urls whitespace in compatibility mode': cssContext({
'keeps spaces as they are': '*{background:url(test.png) no-repeat}'
}, { compatibility: 'ie8' }),
+ 'urls quotes in compatibility mode': cssContext({
+ 'keeps quotes as they are': [
+ 'div{background:url("test.png")}',
+ 'div{background:url("test.png")}'
+ ]
+ }, { compatibility: { properties: { urlQuotes: true } } }),
'urls rewriting - no root or target': cssContext({
'no @import': [
'a{background:url(test/fixtures/partials/extra/down.gif) no-repeat}',
assert.isFalse(options.properties.backgroundSizeMerging);
assert.isTrue(options.properties.merging);
assert.isFalse(options.properties.spaceAfterClosingBrace);
+ assert.isFalse(options.properties.urlQuotes);
assert.isTrue(options.units.rem);
assert.isTrue(options.colors.opacity);
assert.deepEqual(options.selectors.special, /(\-moz\-|\-ms\-|\-o\-|\-webkit\-|:dir\([a-z-]*\)|:first(?![a-z-])|:fullscreen|:left|:read-only|:read-write|:right)/);
assert.isFalse(options.properties.backgroundSizeMerging);
assert.isFalse(options.properties.merging);
assert.isTrue(options.properties.spaceAfterClosingBrace);
+ assert.isFalse(options.properties.urlQuotes);
assert.isTrue(options.properties.zeroUnits);
assert.isFalse(options.units.rem);
assert.isFalse(options.colors.opacity);
assert.isFalse(options.properties.backgroundSizeMerging);
assert.isFalse(options.properties.merging);
assert.isTrue(options.properties.spaceAfterClosingBrace);
+ assert.isFalse(options.properties.urlQuotes);
assert.isTrue(options.properties.zeroUnits);
assert.isFalse(options.units.rem);
assert.isFalse(options.colors.opacity);