Skip to content

Instantly share code, notes, and snippets.

@mihawk90
Last active December 18, 2015 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mihawk90/5821511 to your computer and use it in GitHub Desktop.
Save mihawk90/5821511 to your computer and use it in GitHub Desktop.
A simple Macro for replacing Hex Color values with RGBA values in Komodo Select the color value, press macro and it replaces the value automatically
//inspired by http://stackoverflow.com/a/5624139
function hexToRgb(hex) {
// Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
hex = hex.replace(shorthandRegex, function(m, r, g, b) {
return r + r + g + g + b + b;
});
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? "rgba("+
parseInt(result[1], 16)+", "+ //red
parseInt(result[2], 16)+", "+ //green
parseInt(result[3], 16)+", 1)" //blue + alpha
: null;
}
ko.views.manager.currentView.scimoz.replaceSel(hexToRgb(ko.views.manager.currentView.scimoz.selText));
// to find each consecutive hex-color of the same value
//ko.find.replaceInMacro(window, 0, ko.views.manager.currentView.scimoz.selText, hexToRgb(ko.views.manager.currentView.scimoz.selText), 0, 1, false, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment