css-loader 1.0.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +72 -0
- package/README.md +442 -206
- package/dist/CssSyntaxError.js +38 -0
- package/dist/Warning.js +32 -0
- package/dist/cjs.js +5 -0
- package/dist/index.js +266 -0
- package/dist/options.json +93 -0
- package/dist/plugins/index.js +31 -0
- package/dist/plugins/postcss-icss-parser.js +101 -0
- package/dist/plugins/postcss-import-parser.js +110 -0
- package/dist/plugins/postcss-url-parser.js +155 -0
- package/dist/runtime/api.js +85 -0
- package/dist/runtime/url-escape.js +20 -0
- package/dist/utils.js +72 -0
- package/package.json +105 -36
- package/index.js +0 -5
- package/lib/compile-exports.js +0 -51
- package/lib/css-base.js +0 -76
- package/lib/getImportPrefix.js +0 -14
- package/lib/getLocalIdent.js +0 -23
- package/lib/loader.js +0 -144
- package/lib/localsLoader.js +0 -44
- package/lib/processCss.js +0 -244
- package/lib/url/escape.js +0 -16
- package/locals.js +0 -5
package/lib/loader.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
-
Author Tobias Koppers @sokra
|
|
4
|
-
*/
|
|
5
|
-
var loaderUtils = require("loader-utils");
|
|
6
|
-
var processCss = require("./processCss");
|
|
7
|
-
var getImportPrefix = require("./getImportPrefix");
|
|
8
|
-
var compileExports = require("./compile-exports");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
module.exports = function(content, map) {
|
|
12
|
-
var callback = this.async();
|
|
13
|
-
var query = loaderUtils.getOptions(this) || {};
|
|
14
|
-
var moduleMode = query.modules;
|
|
15
|
-
var camelCaseKeys = query.camelCase;
|
|
16
|
-
var sourceMap = query.sourceMap || false;
|
|
17
|
-
|
|
18
|
-
if(sourceMap) {
|
|
19
|
-
if (map) {
|
|
20
|
-
if (typeof map === "string") {
|
|
21
|
-
map = JSON.stringify(map);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (map.sources) {
|
|
25
|
-
map.sources = map.sources.map(function (source) {
|
|
26
|
-
return source.replace(/\\/g, '/');
|
|
27
|
-
});
|
|
28
|
-
map.sourceRoot = '';
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
} else {
|
|
32
|
-
// Some loaders (example `"postcss-loader": "1.x.x"`) always generates source map, we should remove it
|
|
33
|
-
map = null;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
processCss(content, map, {
|
|
37
|
-
mode: moduleMode ? "local" : "global",
|
|
38
|
-
from: loaderUtils.getRemainingRequest(this).split("!").pop(),
|
|
39
|
-
to: loaderUtils.getCurrentRequest(this).split("!").pop(),
|
|
40
|
-
query: query,
|
|
41
|
-
loaderContext: this,
|
|
42
|
-
sourceMap: sourceMap
|
|
43
|
-
}, function(err, result) {
|
|
44
|
-
if(err) return callback(err);
|
|
45
|
-
|
|
46
|
-
var cssAsString = JSON.stringify(result.source);
|
|
47
|
-
|
|
48
|
-
// for importing CSS
|
|
49
|
-
var importUrlPrefix = getImportPrefix(this, query);
|
|
50
|
-
|
|
51
|
-
var alreadyImported = {};
|
|
52
|
-
var importJs = result.importItems.map(function(imp) {
|
|
53
|
-
// fixes #781 when importing `url(filename.css )`
|
|
54
|
-
imp.url = imp.url.trim();
|
|
55
|
-
return imp;
|
|
56
|
-
}).filter(function(imp) {
|
|
57
|
-
if(!imp.mediaQuery) {
|
|
58
|
-
if(alreadyImported[imp.url])
|
|
59
|
-
return false;
|
|
60
|
-
alreadyImported[imp.url] = true;
|
|
61
|
-
}
|
|
62
|
-
return true;
|
|
63
|
-
}).map(function(imp) {
|
|
64
|
-
if(!loaderUtils.isUrlRequest(imp.url)) {
|
|
65
|
-
return "exports.push([module.id, " +
|
|
66
|
-
JSON.stringify("@import url(" + imp.url + ");") + ", " +
|
|
67
|
-
JSON.stringify(imp.mediaQuery) + "]);";
|
|
68
|
-
} else {
|
|
69
|
-
var importUrl = importUrlPrefix + imp.url;
|
|
70
|
-
return "exports.i(require(" + loaderUtils.stringifyRequest(this, importUrl) + "), " + JSON.stringify(imp.mediaQuery) + ");";
|
|
71
|
-
}
|
|
72
|
-
}, this).join("\n");
|
|
73
|
-
|
|
74
|
-
function importItemMatcher(item) {
|
|
75
|
-
var match = result.importItemRegExp.exec(item);
|
|
76
|
-
var idx = +match[1];
|
|
77
|
-
var importItem = result.importItems[idx];
|
|
78
|
-
var importUrl = importUrlPrefix + importItem.url;
|
|
79
|
-
return "\" + require(" + loaderUtils.stringifyRequest(this, importUrl) + ").locals" +
|
|
80
|
-
"[" + JSON.stringify(importItem.export) + "] + \"";
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
cssAsString = cssAsString.replace(result.importItemRegExpG, importItemMatcher.bind(this));
|
|
84
|
-
|
|
85
|
-
// helper for ensuring valid CSS strings from requires
|
|
86
|
-
var urlEscapeHelper = "";
|
|
87
|
-
|
|
88
|
-
if(query.url !== false && result.urlItems.length > 0) {
|
|
89
|
-
urlEscapeHelper = "var escape = require(" + loaderUtils.stringifyRequest(this, require.resolve("./url/escape.js")) + ");\n";
|
|
90
|
-
|
|
91
|
-
cssAsString = cssAsString.replace(result.urlItemRegExpG, function(item) {
|
|
92
|
-
var match = result.urlItemRegExp.exec(item);
|
|
93
|
-
var idx = +match[1];
|
|
94
|
-
var urlItem = result.urlItems[idx];
|
|
95
|
-
var url = urlItem.url;
|
|
96
|
-
idx = url.indexOf("?#");
|
|
97
|
-
if(idx < 0) idx = url.indexOf("#");
|
|
98
|
-
var urlRequest;
|
|
99
|
-
if(idx > 0) { // idx === 0 is catched by isUrlRequest
|
|
100
|
-
// in cases like url('webfont.eot?#iefix')
|
|
101
|
-
urlRequest = url.substr(0, idx);
|
|
102
|
-
return "\" + escape(require(" + loaderUtils.stringifyRequest(this, urlRequest) + ")) + \"" +
|
|
103
|
-
url.substr(idx);
|
|
104
|
-
}
|
|
105
|
-
urlRequest = url;
|
|
106
|
-
return "\" + escape(require(" + loaderUtils.stringifyRequest(this, urlRequest) + ")) + \"";
|
|
107
|
-
}.bind(this));
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
var exportJs = compileExports(result, importItemMatcher.bind(this), camelCaseKeys);
|
|
111
|
-
if (exportJs) {
|
|
112
|
-
exportJs = "exports.locals = " + exportJs + ";";
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
var moduleJs;
|
|
116
|
-
if(sourceMap && result.map) {
|
|
117
|
-
// add a SourceMap
|
|
118
|
-
map = result.map;
|
|
119
|
-
if(map.sources) {
|
|
120
|
-
map.sources = map.sources.map(function(source) {
|
|
121
|
-
return source.split("!").pop().replace(/\\/g, '/');
|
|
122
|
-
}, this);
|
|
123
|
-
map.sourceRoot = "";
|
|
124
|
-
}
|
|
125
|
-
map.file = map.file.split("!").pop().replace(/\\/g, '/');
|
|
126
|
-
map = JSON.stringify(map);
|
|
127
|
-
moduleJs = "exports.push([module.id, " + cssAsString + ", \"\", " + map + "]);";
|
|
128
|
-
} else {
|
|
129
|
-
moduleJs = "exports.push([module.id, " + cssAsString + ", \"\"]);";
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// embed runtime
|
|
133
|
-
callback(null, urlEscapeHelper +
|
|
134
|
-
"exports = module.exports = require(" +
|
|
135
|
-
loaderUtils.stringifyRequest(this, require.resolve("./css-base.js")) +
|
|
136
|
-
")(" + sourceMap + ");\n" +
|
|
137
|
-
"// imports\n" +
|
|
138
|
-
importJs + "\n\n" +
|
|
139
|
-
"// module\n" +
|
|
140
|
-
moduleJs + "\n\n" +
|
|
141
|
-
"// exports\n" +
|
|
142
|
-
exportJs);
|
|
143
|
-
}.bind(this));
|
|
144
|
-
};
|
package/lib/localsLoader.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
-
Author Tobias Koppers @sokra
|
|
4
|
-
*/
|
|
5
|
-
var loaderUtils = require("loader-utils");
|
|
6
|
-
var processCss = require("./processCss");
|
|
7
|
-
var getImportPrefix = require("./getImportPrefix");
|
|
8
|
-
var compileExports = require("./compile-exports");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
module.exports = function(content) {
|
|
12
|
-
var callback = this.async();
|
|
13
|
-
var query = loaderUtils.getOptions(this) || {};
|
|
14
|
-
var moduleMode = query.modules;
|
|
15
|
-
var camelCaseKeys = query.camelCase;
|
|
16
|
-
|
|
17
|
-
processCss(content, null, {
|
|
18
|
-
mode: moduleMode ? "local" : "global",
|
|
19
|
-
query: query,
|
|
20
|
-
loaderContext: this,
|
|
21
|
-
}, function(err, result) {
|
|
22
|
-
if(err) return callback(err);
|
|
23
|
-
|
|
24
|
-
// for importing CSS
|
|
25
|
-
var importUrlPrefix = getImportPrefix(this, query);
|
|
26
|
-
|
|
27
|
-
function importItemMatcher(item) {
|
|
28
|
-
var match = result.importItemRegExp.exec(item);
|
|
29
|
-
var idx = +match[1];
|
|
30
|
-
var importItem = result.importItems[idx];
|
|
31
|
-
var importUrl = importUrlPrefix + importItem.url;
|
|
32
|
-
return "\" + require(" + loaderUtils.stringifyRequest(this, importUrl) + ")" +
|
|
33
|
-
"[" + JSON.stringify(importItem.export) + "] + \"";
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
var exportJs = compileExports(result, importItemMatcher.bind(this), camelCaseKeys);
|
|
37
|
-
if (exportJs) {
|
|
38
|
-
exportJs = "module.exports = " + exportJs + ";";
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
callback(null, exportJs);
|
|
43
|
-
}.bind(this));
|
|
44
|
-
};
|
package/lib/processCss.js
DELETED
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
-
Author Tobias Koppers @sokra
|
|
4
|
-
*/
|
|
5
|
-
var formatCodeFrame = require("babel-code-frame");
|
|
6
|
-
var Tokenizer = require("css-selector-tokenizer");
|
|
7
|
-
var postcss = require("postcss");
|
|
8
|
-
var loaderUtils = require("loader-utils");
|
|
9
|
-
var getLocalIdent = require("./getLocalIdent");
|
|
10
|
-
|
|
11
|
-
var icssUtils = require('icss-utils');
|
|
12
|
-
var localByDefault = require("postcss-modules-local-by-default");
|
|
13
|
-
var extractImports = require("postcss-modules-extract-imports");
|
|
14
|
-
var modulesScope = require("postcss-modules-scope");
|
|
15
|
-
var modulesValues = require("postcss-modules-values");
|
|
16
|
-
var valueParser = require('postcss-value-parser');
|
|
17
|
-
|
|
18
|
-
var parserPlugin = postcss.plugin("css-loader-parser", function(options) {
|
|
19
|
-
return function(css) {
|
|
20
|
-
var imports = {};
|
|
21
|
-
var exports = {};
|
|
22
|
-
var importItems = [];
|
|
23
|
-
var urlItems = [];
|
|
24
|
-
|
|
25
|
-
function replaceImportsInString(str) {
|
|
26
|
-
if(options.import) {
|
|
27
|
-
var tokens = valueParser(str);
|
|
28
|
-
tokens.walk(function (node) {
|
|
29
|
-
if (node.type !== 'word') {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
var token = node.value;
|
|
33
|
-
var importIndex = imports["$" + token];
|
|
34
|
-
if(typeof importIndex === "number") {
|
|
35
|
-
node.value = "___CSS_LOADER_IMPORT___" + importIndex + "___";
|
|
36
|
-
}
|
|
37
|
-
})
|
|
38
|
-
return tokens.toString();
|
|
39
|
-
}
|
|
40
|
-
return str;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if(options.import) {
|
|
44
|
-
css.walkAtRules(/^import$/i, function(rule) {
|
|
45
|
-
var values = Tokenizer.parseValues(rule.params);
|
|
46
|
-
var url = values.nodes[0].nodes[0];
|
|
47
|
-
if(url && url.type === "url") {
|
|
48
|
-
url = url.url;
|
|
49
|
-
} else if(url && url.type === "string") {
|
|
50
|
-
url = url.value;
|
|
51
|
-
} else throw rule.error("Unexpected format " + rule.params);
|
|
52
|
-
if (!url.replace(/\s/g, '').length) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
values.nodes[0].nodes.shift();
|
|
56
|
-
var mediaQuery = Tokenizer.stringifyValues(values);
|
|
57
|
-
|
|
58
|
-
if(loaderUtils.isUrlRequest(url)) {
|
|
59
|
-
url = loaderUtils.urlToRequest(url);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
importItems.push({
|
|
63
|
-
url: url,
|
|
64
|
-
mediaQuery: mediaQuery
|
|
65
|
-
});
|
|
66
|
-
rule.remove();
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
var icss = icssUtils.extractICSS(css);
|
|
71
|
-
exports = icss.icssExports;
|
|
72
|
-
Object.keys(icss.icssImports).forEach(function(key) {
|
|
73
|
-
var url = loaderUtils.parseString(key);
|
|
74
|
-
Object.keys(icss.icssImports[key]).forEach(function(prop) {
|
|
75
|
-
imports["$" + prop] = importItems.length;
|
|
76
|
-
importItems.push({
|
|
77
|
-
url: url,
|
|
78
|
-
export: icss.icssImports[key][prop]
|
|
79
|
-
});
|
|
80
|
-
})
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
Object.keys(exports).forEach(function(exportName) {
|
|
84
|
-
exports[exportName] = replaceImportsInString(exports[exportName]);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
function processNode(item) {
|
|
88
|
-
switch (item.type) {
|
|
89
|
-
case "value":
|
|
90
|
-
item.nodes.forEach(processNode);
|
|
91
|
-
break;
|
|
92
|
-
case "nested-item":
|
|
93
|
-
item.nodes.forEach(processNode);
|
|
94
|
-
break;
|
|
95
|
-
case "item":
|
|
96
|
-
var importIndex = imports["$" + item.name];
|
|
97
|
-
if (typeof importIndex === "number") {
|
|
98
|
-
item.name = "___CSS_LOADER_IMPORT___" + importIndex + "___";
|
|
99
|
-
}
|
|
100
|
-
break;
|
|
101
|
-
case "url":
|
|
102
|
-
if (options.url && item.url.replace(/\s/g, '').length && !/^#/.test(item.url) && loaderUtils.isUrlRequest(item.url)) {
|
|
103
|
-
// Strip quotes, they will be re-added if the module needs them
|
|
104
|
-
item.stringType = "";
|
|
105
|
-
delete item.innerSpacingBefore;
|
|
106
|
-
delete item.innerSpacingAfter;
|
|
107
|
-
var url = item.url;
|
|
108
|
-
item.url = "___CSS_LOADER_URL___" + urlItems.length + "___";
|
|
109
|
-
urlItems.push({
|
|
110
|
-
url: url
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
break;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
css.walkDecls(function(decl) {
|
|
118
|
-
var values = Tokenizer.parseValues(decl.value);
|
|
119
|
-
values.nodes.forEach(function(value) {
|
|
120
|
-
value.nodes.forEach(processNode);
|
|
121
|
-
});
|
|
122
|
-
decl.value = Tokenizer.stringifyValues(values);
|
|
123
|
-
});
|
|
124
|
-
css.walkAtRules(function(atrule) {
|
|
125
|
-
if(typeof atrule.params === "string") {
|
|
126
|
-
atrule.params = replaceImportsInString(atrule.params);
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
options.importItems = importItems;
|
|
131
|
-
options.urlItems = urlItems;
|
|
132
|
-
options.exports = exports;
|
|
133
|
-
};
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
module.exports = function processCss(inputSource, inputMap, options, callback) {
|
|
137
|
-
var query = options.query;
|
|
138
|
-
var context = query.context;
|
|
139
|
-
var localIdentName = query.localIdentName || "[hash:base64]";
|
|
140
|
-
var localIdentRegExp = query.localIdentRegExp;
|
|
141
|
-
|
|
142
|
-
var customGetLocalIdent = query.getLocalIdent || getLocalIdent;
|
|
143
|
-
|
|
144
|
-
var parserOptions = {
|
|
145
|
-
mode: options.mode,
|
|
146
|
-
url: query.url !== false,
|
|
147
|
-
import: query.import !== false,
|
|
148
|
-
resolve: options.resolve
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
var pipeline = postcss([
|
|
152
|
-
modulesValues,
|
|
153
|
-
localByDefault({
|
|
154
|
-
mode: options.mode,
|
|
155
|
-
rewriteUrl: function(global, url) {
|
|
156
|
-
if(parserOptions.url){
|
|
157
|
-
url = url.trim();
|
|
158
|
-
|
|
159
|
-
if(!url.replace(/\s/g, '').length || !loaderUtils.isUrlRequest(url)) {
|
|
160
|
-
return url;
|
|
161
|
-
}
|
|
162
|
-
if(global) {
|
|
163
|
-
return loaderUtils.urlToRequest(url);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
return url;
|
|
167
|
-
}
|
|
168
|
-
}),
|
|
169
|
-
extractImports(),
|
|
170
|
-
modulesScope({
|
|
171
|
-
generateScopedName: function generateScopedName (exportName) {
|
|
172
|
-
return customGetLocalIdent(options.loaderContext, localIdentName, exportName, {
|
|
173
|
-
regExp: localIdentRegExp,
|
|
174
|
-
hashPrefix: query.hashPrefix || "",
|
|
175
|
-
context: context
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
}),
|
|
179
|
-
parserPlugin(parserOptions)
|
|
180
|
-
]);
|
|
181
|
-
|
|
182
|
-
pipeline.process(inputSource, {
|
|
183
|
-
// we need a prefix to avoid path rewriting of PostCSS
|
|
184
|
-
from: "/css-loader!" + options.from,
|
|
185
|
-
to: options.to,
|
|
186
|
-
map: options.sourceMap ? {
|
|
187
|
-
prev: inputMap,
|
|
188
|
-
sourcesContent: true,
|
|
189
|
-
inline: false,
|
|
190
|
-
annotation: false
|
|
191
|
-
} : null
|
|
192
|
-
}).then(function(result) {
|
|
193
|
-
callback(null, {
|
|
194
|
-
source: result.css,
|
|
195
|
-
map: result.map && result.map.toJSON(),
|
|
196
|
-
exports: parserOptions.exports,
|
|
197
|
-
importItems: parserOptions.importItems,
|
|
198
|
-
importItemRegExpG: /___CSS_LOADER_IMPORT___([0-9]+)___/g,
|
|
199
|
-
importItemRegExp: /___CSS_LOADER_IMPORT___([0-9]+)___/,
|
|
200
|
-
urlItems: parserOptions.urlItems,
|
|
201
|
-
urlItemRegExpG: /___CSS_LOADER_URL___([0-9]+)___/g,
|
|
202
|
-
urlItemRegExp: /___CSS_LOADER_URL___([0-9]+)___/
|
|
203
|
-
});
|
|
204
|
-
}).catch(function(err) {
|
|
205
|
-
if (err.name === 'CssSyntaxError') {
|
|
206
|
-
var wrappedError = new CSSLoaderError(
|
|
207
|
-
'Syntax Error',
|
|
208
|
-
err.reason,
|
|
209
|
-
err.line != null && err.column != null
|
|
210
|
-
? {line: err.line, column: err.column}
|
|
211
|
-
: null,
|
|
212
|
-
err.input.source
|
|
213
|
-
);
|
|
214
|
-
callback(wrappedError);
|
|
215
|
-
} else {
|
|
216
|
-
callback(err);
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
function formatMessage(message, loc, source) {
|
|
222
|
-
var formatted = message;
|
|
223
|
-
if (loc) {
|
|
224
|
-
formatted = formatted
|
|
225
|
-
+ ' (' + loc.line + ':' + loc.column + ')';
|
|
226
|
-
}
|
|
227
|
-
if (loc && source) {
|
|
228
|
-
formatted = formatted
|
|
229
|
-
+ '\n\n' + formatCodeFrame(source, loc.line, loc.column) + '\n';
|
|
230
|
-
}
|
|
231
|
-
return formatted;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
function CSSLoaderError(name, message, loc, source, error) {
|
|
235
|
-
Error.call(this);
|
|
236
|
-
Error.captureStackTrace(this, CSSLoaderError);
|
|
237
|
-
this.name = name;
|
|
238
|
-
this.error = error;
|
|
239
|
-
this.message = formatMessage(message, loc, source);
|
|
240
|
-
this.hideStack = true;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
CSSLoaderError.prototype = Object.create(Error.prototype);
|
|
244
|
-
CSSLoaderError.prototype.constructor = CSSLoaderError;
|
package/lib/url/escape.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
module.exports = function escape(url) {
|
|
2
|
-
if (typeof url !== 'string') {
|
|
3
|
-
return url
|
|
4
|
-
}
|
|
5
|
-
// If url is already wrapped in quotes, remove them
|
|
6
|
-
if (/^['"].*['"]$/.test(url)) {
|
|
7
|
-
url = url.slice(1, -1);
|
|
8
|
-
}
|
|
9
|
-
// Should url be wrapped?
|
|
10
|
-
// See https://drafts.csswg.org/css-values-3/#urls
|
|
11
|
-
if (/["'() \t\n]/.test(url)) {
|
|
12
|
-
return '"' + url.replace(/"/g, '\\"').replace(/\n/g, '\\n') + '"'
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return url
|
|
16
|
-
}
|