Skip to content

Commit

Permalink
Fixes #940 - handles more font keywords.
Browse files Browse the repository at this point in the history
Why:

* The list wasn't exhaustive, hopefully the new one is.
  • Loading branch information
jakubpawlowicz committed May 9, 2017
1 parent 8d222fb commit 321c56e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
5 changes: 5 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[4.1.2 / 2017-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v4.1.1...4.1)
==================

* Fixed issue [#940](https://github.com/jakubpawlowicz/clean-css/issues/940) - handling more `font` keywords.

[4.1.1 / 2017-05-08](https://github.com/jakubpawlowicz/clean-css/compare/v4.1.0...v4.1.1)
==================

Expand Down
6 changes: 3 additions & 3 deletions lib/optimizer/level-2/break-up.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,13 @@ function font(property, compactable, validator) {
throw new InvalidPropertyError('Missing font values at ' + formatPosition(property.all[property.position][1][2][0]) + '. Ignoring.');
}

if (values.length == 1 && (validator.isFontKeyword(values[0][1]) || validator.isPrefixed(values[0][1]))) {
values[0][1] = Marker.INTERNAL + values[0][1];
if (values.length == 1 && values[0][1] == 'inherit') {
style.value = variant.value = weight.value = stretch.value = size.value = height.value = family.value = values;
return components;
}

if (values.length == 1 && values[0][1] == 'inherit') {
if (values.length == 1 && (validator.isFontKeyword(values[0][1]) || validator.isGlobal(values[0][1]) || validator.isPrefixed(values[0][1]))) {
values[0][1] = Marker.INTERNAL + values[0][1];
style.value = variant.value = weight.value = stretch.value = size.value = height.value = family.value = values;
return components;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/optimizer/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ var Keywords = {
'menu',
'message-box',
'small-caption',
'status-bar'
'status-bar',
'unset'
],
'font-size': [
'large',
Expand Down
42 changes: 42 additions & 0 deletions test/optimizer/level-2/break-up-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1475,6 +1475,48 @@ vows.describe(breakUp)
assert.deepEqual(components[6].value, [['property-value', '-clean-css-icon']]);
}
},
'unset font': {
'topic': function () {
return _breakUp([
[
'property',
['property-name', 'font'],
['property-value', 'unset']
]
]);
},
'has 7 components': function (components) {
assert.lengthOf(components, 7);
},
'has font-style': function (components) {
assert.equal(components[0].name, 'font-style');
assert.deepEqual(components[0].value, [['property-value', '-clean-css-unset']]);
},
'has font-variant': function (components) {
assert.equal(components[1].name, 'font-variant');
assert.deepEqual(components[1].value, [['property-value', '-clean-css-unset']]);
},
'has font-weight': function (components) {
assert.equal(components[2].name, 'font-weight');
assert.deepEqual(components[2].value, [['property-value', '-clean-css-unset']]);
},
'has font-stretch': function (components) {
assert.equal(components[3].name, 'font-stretch');
assert.deepEqual(components[3].value, [['property-value', '-clean-css-unset']]);
},
'has font-size': function (components) {
assert.equal(components[4].name, 'font-size');
assert.deepEqual(components[4].value, [['property-value', '-clean-css-unset']]);
},
'has line-height': function (components) {
assert.equal(components[5].name, 'line-height');
assert.deepEqual(components[5].value, [['property-value', '-clean-css-unset']]);
},
'has font-family': function (components) {
assert.equal(components[6].name, 'font-family');
assert.deepEqual(components[6].value, [['property-value', '-clean-css-unset']]);
}
},
'system font with vendor prefix': {
'topic': function () {
return _breakUp([
Expand Down

0 comments on commit 321c56e

Please sign in to comment.