Fixes #149 - shorthand font property with optional styles.
authorGoalSmashers <jakub@goalsmashers.com>
Fri, 27 Sep 2013 15:36:53 +0000 (17:36 +0200)
committerGoalSmashers <jakub@goalsmashers.com>
Sun, 29 Sep 2013 11:10:08 +0000 (13:10 +0200)
* It does not offer optimal minification by not handling 'font:normal normal normal <size> <font-family' case.
* Will be further improved to support mentioned case.

History.md
lib/clean.js
test/unit-test.js

index 58e281e..a3e9d96 100644 (file)
@@ -3,6 +3,11 @@
 
 * Adds simplified and more advanced text escaping / restoring via EscapeStore class.
 
+1.1.2 / 2013-xx-xx (UNRELEASED)
+==================
+
+* Fixed issue [#149](https://github.com/GoalSmashers/clean-css/issues/149) - shorthand font property.
+
 1.1.1 / 2013-09-07
 ==================
 
index 6e849c8..f91aca8 100644 (file)
@@ -182,11 +182,14 @@ var CleanCSS = {
     });
 
     // replace font weight with numerical value
-    replace(/(font|font\-weight):(normal|bold)([ ;\}!])/g, function(match, property, weight, suffix) {
+    replace(/(font\-weight|font):(normal|bold)([ ;\}!])(\w*)/g, function(match, property, weight, suffix, next) {
+      if (suffix == ' ' && next.length > 0 && !/[.\d]/.test(next))
+        return match;
+
       if (weight == 'normal')
-        return property + ':400' + suffix;
+        return property + ':400' + suffix + next;
       else if (weight == 'bold')
-        return property + ':700' + suffix;
+        return property + ':700' + suffix + next;
       else
         return match;
     });
index 096aac9..bdb6106 100644 (file)
@@ -600,10 +600,15 @@ vows.describe('clean-units').addBatch({
       'font:normal 13px/20px "Helvetica Neue",Helvetica,Arial,sans-serif',
       'font:400 13px/20px "Helvetica Neue",Helvetica,Arial,sans-serif'
     ],
+    'font weight in font declarations with fraction units': [
+      'font:bold .9rem Helvetica',
+      'font:700 .9rem Helvetica'
+    ],
     'multiple changes': [
-      'p{font-weight:bold;width:100%;font:normal}',
-      'p{font-weight:700;width:100%;font:400}'
-    ]
+      'p{font-weight:bold;width:100%;font:normal 12px Helvetica}',
+      'p{font-weight:700;width:100%;font:400 12px Helvetica}'
+    ],
+    'font weight in extended font declarations': 'font:normal normal normal 13px/20px Helvetica'
   }),
   'urls': cssContext({
     'keep urls without parentheses unchanged': 'a{background:url(/images/blank.png) 0 0 no-repeat}',