Skip to content

Commit

Permalink
Add currentColor param to convertColors plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
scurker committed Mar 21, 2016
1 parent e69f0a2 commit 97ab6c2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
9 changes: 8 additions & 1 deletion plugins/convertColors.js
Expand Up @@ -7,6 +7,7 @@ exports.active = true;
exports.description = 'converts colors: rgb() to #rrggbb and #rrggbb to #rgb';

exports.params = {
currentColor: false,
names2hex: true,
rgb2hex: true,
shorthex: true,
Expand All @@ -17,7 +18,8 @@ var collections = require('./_collections'),
rNumber = '([+-]?(?:\\d*\\.\\d+|\\d+\\.?)%?)',
rComma = '\\s*,\\s*',
regRGB = new RegExp('^rgb\\(\\s*' + rNumber + rComma + rNumber + rComma + rNumber + '\\s*\\)$'),
regHEX = /^\#(([a-fA-F0-9])\2){3}$/;
regHEX = /^\#(([a-fA-F0-9])\2){3}$/,
none = /none/i;

/**
* Convert different colors formats in element attributes to hex.
Expand Down Expand Up @@ -56,6 +58,11 @@ exports.fn = function(item, params) {
var val = attr.value,
match;

// Convert colors to currentColor
if (params.currentColor && (match = !val.match(none))) {
val = 'currentColor';
}

// Convert color name keyword to long hex
if (params.names2hex && val.toLowerCase() in collections.colorsNames) {
val = collections.colorsNames[val.toLowerCase()];
Expand Down
25 changes: 25 additions & 0 deletions test/plugins/convertColors.04.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 97ab6c2

Please sign in to comment.