From cd4b5c8abe745614d4d36155d6c1d9655b363edd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?=
 <lorenz-dev@lgh-alumni.de>
Date: Thu, 31 Jul 2014 14:20:42 +0100
Subject: [PATCH] Display HTML colour codes inline

---
 css/glowingbear.css |  9 +++++++++
 index.html          |  2 +-
 js/glowingbear.js   | 16 ++++++++++++++++
 3 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/css/glowingbear.css b/css/glowingbear.css
index 9ba74c6..440b008 100644
--- a/css/glowingbear.css
+++ b/css/glowingbear.css
@@ -346,6 +346,15 @@ div.embed img.embed {
     max-width: 100%;
 }
 
+div.colourbox {
+    display: inline-block;
+    border-radius: 3px;
+    border: 1px solid #bbb;
+    width: 14px;
+    height: 14px;
+    margin-bottom: -2px;
+}
+
 
 table.notimestamp td.time {
     display: none !important;
diff --git a/index.html b/index.html
index 6178247..916e912 100644
--- a/index.html
+++ b/index.html
@@ -255,7 +255,7 @@ $ openssl req -nodes -newkey rsa:4096 -keyout relay.pem -x509 -days 365 -out rel
               <td class="prefix"><a ng-click="addMention(bufferline.prefix)"><span ng-repeat="part in bufferline.prefix" bo-class="part.classes" bo-html="part.text"></span></a></td>
               <td class="message">
                 <div ng-repeat="metadata in bufferline.metadata" plugin data="metadata"></div>
-                <span ng-repeat="part in bufferline.content" class="text" bo-class="part.classes" bo-html="part.text|irclinky:'_blank'"></span>
+                <span ng-repeat="part in bufferline.content" class="text" bo-class="part.classes" bo-html="part.text | irclinky:'_blank' | inlinecolour"></span>
               </td>
             </tr>
             <tr class="readmarker" ng-if="activeBuffer().lastSeen==$index">
diff --git a/js/glowingbear.js b/js/glowingbear.js
index 3f442a3..f682e0b 100644
--- a/js/glowingbear.js
+++ b/js/glowingbear.js
@@ -49,6 +49,22 @@ weechat.filter('irclinky', ['$filter', function($filter) {
     };
 }]);
 
+weechat.filter('inlinecolour', function() {
+    'use strict';
+
+    return function(text) {
+        if (!text) {
+            return text;
+        }
+
+        // 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);
+    };
+});
+
 weechat.factory('handlers', ['$rootScope', '$log', 'models', 'plugins', function($rootScope, $log, models, plugins) {
 
     var handleBufferClosing = function(message) {