Skip to content

Commit b82bcc3

Browse files
committed
Merge pull request reworkcss#1 from elegantcoder/master
improved atimport() for other at-rules.
2 parents aa71e67 + e2fbdd9 commit b82bcc3

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

index.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,28 @@ module.exports = function(css){
200200
*/
201201

202202
function atimport() {
203-
var m = match(/^@import *([^;\n]+);\s*/);
203+
return _atruleSimple('import')
204+
}
205+
206+
/**
207+
* Parse charset
208+
*/
209+
210+
function atcharset() {
211+
return _atruleSimple('charset');
212+
}
213+
214+
/**
215+
* Parse non-block at-rules
216+
*/
217+
218+
function _atruleSimple(ruleName) {
219+
var m = match(new RegExp('^@'+ruleName+' *([^;\\n]+);\\s*'));
204220
if (!m) return;
205-
return { import: m[1].trim() };
221+
222+
var ret = {}
223+
ret[ruleName] = m[1].trim();
224+
return ret;
206225
}
207226

208227
/**
@@ -233,7 +252,8 @@ module.exports = function(css){
233252
function atrule() {
234253
return keyframes()
235254
|| media()
236-
|| atimport();
255+
|| atimport()
256+
|| atcharset();
237257
}
238258

239259
/**
@@ -248,4 +268,4 @@ module.exports = function(css){
248268
}
249269

250270
return stylesheet();
251-
};
271+
};

test/cases/charset.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@charset "UTF-8"; /* Set the encoding of the style sheet to Unicode UTF-8*/
2+
@charset 'iso-8859-15'; /* Set the encoding of the style sheet to Latin-9 (Western European languages, with euro sign) */

test/cases/charset.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"stylesheet": {
3+
"rules": [
4+
{
5+
"charset": "\"UTF-8\""
6+
},
7+
{
8+
"charset": "'iso-8859-15'"
9+
}
10+
]
11+
}
12+
}

0 commit comments

Comments
 (0)