Skip to content

Commit 4620250

Browse files
Added @font-face processing
Need to refactor to support all properties mentioned here: https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face
1 parent 9268ce8 commit 4620250

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

index.js

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,61 @@ module.exports = function(css, options){
429429
rules: style
430430
});
431431
}
432+
433+
/**
434+
* Parse font-face.
435+
*/
436+
437+
function atfontface() {
438+
var pos = position();
439+
var m = match(/^@font-face */);
440+
var re = /url\(['"]([^'"]+)['"]\)\s*(?:format\(['"]([^'"]+)['"]\))?/i;
441+
var src = [];
442+
var decls = [];
443+
var srcList;
444+
445+
if (!m) return;
446+
447+
if (!open()) return error("@font-face missing '{'");
448+
449+
var name = match(/^font-family\s*:\s*['"]([^'"]+)['"];/);
450+
451+
if (!name) return error("@font-face missing 'font-family'");
452+
decls.push({
453+
type: 'declaration',
454+
property: 'font-family',
455+
value: trim(name[1])
456+
})
457+
whitespace();
458+
459+
while (srcList = match(/^src\s*:\s*([^;]+);/)) {
460+
var val = trim(srcList[1]);
461+
var set = val.split(',');
462+
463+
decls.push({
464+
type: 'declaration',
465+
property: 'src',
466+
value: val
467+
});
468+
469+
set.forEach(function(item) {
470+
m = re.exec(item);
471+
src.push({
472+
url: trim(m[1]),
473+
format: trim(m[2])
474+
});
475+
})
476+
whitespace();
477+
}
478+
479+
if (!close()) return error("@font-face missing '}'");
480+
481+
return pos({
482+
type: 'fontface',
483+
src: src,
484+
declarations: decls
485+
});
486+
}
432487

433488
/**
434489
* Parse import
@@ -480,7 +535,8 @@ module.exports = function(css, options){
480535
|| atnamespace()
481536
|| atdocument()
482537
|| atpage()
483-
|| athost();
538+
|| athost()
539+
|| atfontface();
484540
}
485541

486542
/**

0 commit comments

Comments
 (0)