From: Jakub Pawlowicz Date: Sun, 25 Sep 2011 10:33:22 +0000 (+0200) Subject: Fixed converting #f00 to red in borders and gradients. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=efe12650a8b92c90bb31aa91e7635f43cbe2a9f8;p=clean-css.git Fixed converting #f00 to red in borders and gradients. --- diff --git a/lib/clean.js b/lib/clean.js index 39ae837b..88a13ad1 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -93,7 +93,7 @@ var CleanCSS = { if (CleanCSS.colors[colorName]) return property + ':' + CleanCSS.colors[colorName]; else return match; }) - replace(/color:#f00/g, 'color:red') // replace #f00 with red as it's shorter + replace(/([: ,\(])#f00/g, '$1red') // replace #f00 with red as it's shorter replace(/font\-weight:(\w+)/g, function(match, weight) { // replace font weight with numerical value if (weight == 'normal') return 'font-weight:400'; else if (weight == 'bold') return 'font-weight:700'; diff --git a/test/unit-test.js b/test/unit-test.js index 659a23ad..1145e319 100644 --- a/test/unit-test.js +++ b/test/unit-test.js @@ -211,10 +211,22 @@ vows.describe('clean-units').addBatch({ 'a{color:white;border-color:black;background-color:fuchsia}p{background:yellow}', 'a{color:#fff;border-color:#000;background-color:#f0f}p{background:#ff0}' ], - 'hex value to color name': [ + 'hex value to color name if shorter': [ 'p{color:#f00}', 'p{color:red}' ], + 'hex value to color name in borders': [ + 'p{border:1px solid #f00}', + 'p{border:1px solid red}' + ], + 'hex value to color name in gradients': [ + 'p{background:-moz-linear-gradient(-90deg,#000,#f00)}', + 'p{background:-moz-linear-gradient(-90deg,#000,red)}' + ], + 'hex value to color name in gradients #2': [ + 'p{background:-webkit-gradient(linear, left top, left bottom, from(#000), to(#f00))}', + 'p{background:-webkit-gradient(linear,left top,left bottom,from(#000),to(red))}' + ], 'border color': [ 'p{border:1px solid #f94311}', 'p{border:1px solid #f94311}'