Merge pull request #527 from glowing-bear/inline-colour-rgb

Add inline colour support for rgb(12,34,56) / rgba(1,2,3,0.4) colours
This commit is contained in:
David Cormier 2015-01-03 10:41:04 -05:00
commit 8eda79e2f3

View file

@ -57,10 +57,12 @@ weechat.filter('inlinecolour', function() {
}
// only match 6-digit colour codes, 3-digit ones have too many false positives (issue numbers, etc)
var hexColourRegex = /(^|[^&])\#([0-9a-f]{6})($|[^\w'"])/gmi;
var substitute = '$1#$2 <div class="colourbox" style="background-color:#$2"></div> $3';
return text.replace(hexColourRegex, substitute);
var hexColourRegex = /(^|[^&])(\#[0-9a-f]{6};?)(?!\w)/gmi;
var rgbColourRegex = /(.?)(rgba?\((?:\s*\d+\s*,){2}\s*\d+\s*(?:,\s*[\d.]+\s*)?\);?)/gmi;
var substitute = '$1$2 <div class="colourbox" style="background-color:$2"></div>';
text = text.replace(hexColourRegex, substitute);
text = text.replace(rgbColourRegex, substitute);
return text;
};
});