postcss-gtk
Version:
Processes GTK+ CSS into browser CSS
60 lines (56 loc) • 1.78 kB
JavaScript
// Generated by CoffeeScript 1.9.1
(function() {
var postcss;
postcss = require("postcss");
module.exports = postcss.plugin("fix-font-declarations", function() {
return function(css, processor) {
var SIZE, WEIGHT;
SIZE = /\d+(?:\.\d+)?(px|em|pt|pc|%|cm|mm|in|)/;
WEIGHT = /bold|light|normal/i;
css.eachDecl(function(decl) {
var fontFamily, the_rest;
if (decl.prop === "font") {
if (decl.value !== "initial") {
the_rest = decl.value.replace(SIZE, function(fontSize) {
decl.parent.insertBefore(decl, {
prop: "font-size",
value: fontSize
});
return "";
}).replace(WEIGHT, function(weight) {
var fontWeight;
fontWeight = weight.toLowerCase();
if (fontWeight === "light") {
fontWeight = "300";
}
decl.parent.insertBefore(decl, {
prop: "font-weight",
value: fontWeight
});
return "";
});
fontFamily = the_rest.trim();
if (fontFamily) {
decl.parent.insertBefore(decl, {
prop: "font-family",
value: '"' + fontFamily + '"'
});
}
return decl.removeSelf();
}
}
});
return css.eachDecl(function(decl) {
var fontSize, ref, unit;
if (decl.prop === "font-size") {
if (decl.value !== "0") {
ref = decl.value.match(SIZE), fontSize = ref[0], unit = ref[1];
if (!unit) {
return decl.value = fontSize + "pt";
}
}
}
});
};
});
}).call(this);