Last active
December 18, 2015 17:49
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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