Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ function sqwish(css, strict) {
// convert longhand hex to shorthand hex
.replace(/#([a-fA-F0-9])\1([a-fA-F0-9])\2([a-fA-F0-9])\3(?![a-fA-F0-9])/g, '#$1$2$3')
// Restore Microsoft longhand hex
.replace(/(Microsoft[^;}]*)#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])(?![a-fA-F0-9])/g, '$1#$2$2$3$3$4$4')
.replace(/(Microsoft[^;}]*)/g, function(match) {
return match.replace(/#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])(?![a-fA-F0-9])/g, '#$1$1$2$2$3$3')
})

// replace longhand values with shorthand '5px 5px 5px 5px' => '5px'
.replace(/\b(\d+[a-z]{2}) \1 \1 \1/gi, '$1')
Expand Down
8 changes: 4 additions & 4 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ sink('basic mode', function (test, ok) {
})

test('IE long hex is kept as long hex', 1, function () {
var input = "body { filter: progid:DXImageTransform.Microsoft.gradient(gradientType=0, startColorstr='#FFF2F2F2', endColorstr='#FFFFFFFF'); }"
, expected = "body{filter:progid:DXImageTransform.Microsoft.gradient(gradientType=0,startColorstr='#FFF2F2F2',endColorstr='#FFFFFFFF')}"
var input = "body { filter: progid:DXImageTransform.Microsoft.gradient(gradientType=0, startColorstr='#FFEEEEEE', endColorstr='#FFFFFFFF'); }"
, expected = "body{filter:progid:DXImageTransform.Microsoft.gradient(gradientType=0,startColorstr='#FFEEEEEE',endColorstr='#FFFFFFFF')}"
, actual = sqwish.minify(input)
ok(actual == expected, 'IE long hexes are kept that way')
})

test('IE 6-digit hex is kept as 6-digit hex', 1, function () {
var input = "body { filter: progid:DXImageTransform.Microsoft.gradient(gradientType=0, startColorstr='#F2F2F2', endColorstr='#FFFFFF'); }"
, expected = "body{filter:progid:DXImageTransform.Microsoft.gradient(gradientType=0,startColorstr='#F2F2F2',endColorstr='#FFFFFF')}"
var input = "body { filter: progid:DXImageTransform.Microsoft.gradient(gradientType=0, startColorstr='#EEEEEE', endColorstr='#FFFFFF'); }"
, expected = "body{filter:progid:DXImageTransform.Microsoft.gradient(gradientType=0,startColorstr='#EEEEEE',endColorstr='#FFFFFF')}"
, actual = sqwish.minify(input)
ok(actual == expected, 'IE 6-digit hexes are kept that way')
})
Expand Down