From 0c20484b5a7b0b04b390f7a640dff1d8c9fe6d75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Tue, 30 Dec 2014 21:06:17 +0100 Subject: [PATCH] Add inline colour support for rgb(12,34,56) / rgba(1,2,3,0.4) colours Also improve the regexes --- js/filters.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/js/filters.js b/js/filters.js index 68f01be..e77933a 100644 --- a/js/filters.js +++ b/js/filters.js @@ -50,10 +50,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
$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
'; + text = text.replace(hexColourRegex, substitute); + text = text.replace(rgbColourRegex, substitute); + return text; }; });