Skip to content

Instantly share code, notes, and snippets.

@sdesai
Created September 23, 2011 00:32
Show Gist options
  • Save sdesai/1236459 to your computer and use it in GitHub Desktop.
Save sdesai/1236459 to your computer and use it in GitHub Desktop.
// Shorten colors from #AABBCC to #ABC. Note that we want to make sure
// the color is not preceded by either ", " or =. Indeed, the property
// filter: chroma(color="#FFFFFF");
// would become
// filter: chroma(color="#FFF");
// which makes the filter break in IE.
BEFORE:
var pattern = /([^"'=\s])(\s*)#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])/gi
BUG: It also compresses ids. e.g #AABBCC { ... } .foo, #AABBCC { ... }
AFTER (make sure we only pick up matches inside a { ... }:
var pattern = /([^"'=\s])(\s*)#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])([^\{]*?\})/gi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment