replace(function moveCharset() {
// get first charset in stylesheet
var match = data.match(/@charset [^;]+;/);
- var firstCharset = match ? match[0] : '';
-
- // remove all charsets
- data = data.replace(/@charset [^;]+;\n?/g, '');
-
- // reattach first charset
- if (firstCharset !== '')
- data = firstCharset + (options.keepBreaks ? lineBreak : '') + data;
+ var firstCharset = match ? match[0] : null;
+ if (!firstCharset)
+ return;
+
+ // reattach first charset and remove all subsequent
+ data = firstCharset +
+ (options.keepBreaks ? lineBreak : '') +
+ data.replace(new RegExp('@charset [^;]+;(' + lineBreak + ')?', 'g'), '');
});
// trim spaces at beginning and end
'charset multiple charsets': [
"@charset 'utf-8';\ndiv :before { display: block }\n@charset 'utf-8';\na { color: #f10 }",
"@charset 'utf-8';" + lineBreak + "div :before{display:block}" + lineBreak + "a{color:#f10}"
+ ],
+ 'charset with double line break': [
+ "@charset 'utf-8';" + lineBreak + lineBreak + "a{}",
+ "@charset 'utf-8';" + lineBreak + "a{}"
]
}, { keepBreaks: true }),
'selectors': cssContext({
'multiple charsets': [
"@charset 'utf-8';div :before { display: block }@charset 'utf-8';a { color: #f10 }",
"@charset 'utf-8';div :before{display:block}a{color:#f10}"
+ ],
+ 'charset and space after': [
+ "@charset 'utf-8';" + lineBreak + lineBreak + "a{}",
+ "@charset 'utf-8';a{}"
]
}),
'important': cssContext({