Skip to content

Commit ea4e561

Browse files
authored
Merge pull request #483 from silkeh/refine-colours
Refine the colours to match the mIRC colours.
2 parents 69f0072 + 7b3afa4 commit ea4e561

File tree

2 files changed

+42
-20
lines changed

2 files changed

+42
-20
lines changed

lib/irc/formatting.js

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,50 @@
22

33
var sanitizeHtml = require('sanitize-html');
44
var htmlNamesToColorCodes = {
5-
white: ['\u000300'],
6-
black: ['\u000301', '\u00031'],
7-
navy: ['\u000302', '\u00032'],
8-
green: ['\u000303', '\u00033'],
9-
red: ['\u000304', '\u000305', '\u00034', '\u00035'],
10-
purple: ['\u000306', '\u00036'],
11-
olive: ['\u000307', '\u00037'],
12-
yellow: ['\u000308', '\u00038'],
13-
lime: ['\u000309', '\u00039'],
14-
teal: ['\u000310'],
15-
aqua: ['\u000311'],
16-
blue: ['\u000312'],
17-
fuchsia: ['\u000313'],
18-
gray: ['\u000314'],
19-
silver: ['\u000315']
5+
white: ['\u000300', '\u00030'],
6+
black: ['\u000301', '\u00031'],
7+
navy: ['\u000302', '\u00032'],
8+
green: ['\u000303', '\u00033'],
9+
red: ['\u000304', '\u00034'],
10+
maroon: ['\u000305', '\u00035'],
11+
purple: ['\u000306', '\u00036'],
12+
orange: ['\u000307', '\u00037'],
13+
yellow: ['\u000308', '\u00038'],
14+
lime: ['\u000309', '\u00039'],
15+
teal: ['\u000310'],
16+
aqua: ['\u000311'],
17+
blue: ['\u000312'],
18+
fuchsia: ['\u000313'],
19+
gray: ['\u000314'],
20+
lightgrey: ['\u000315']
2021
};
22+
23+
// These map the CSS color names to mIRC hex colors
24+
var htmlNamesToHex = {
25+
white: '#FFFFFF',
26+
black: '#000000',
27+
navy: '#00007F',
28+
green: '#009300',
29+
red: '#FF0000',
30+
maroon: '#7F0000',
31+
purple: '#9C009C',
32+
orange: '#FC7F00',
33+
yellow: '#FFFF00',
34+
lime: '#00FC00',
35+
teal: '#009393',
36+
aqua: '#00FFFF',
37+
blue: '#0000FC',
38+
fuchsia: '#FF00FF',
39+
gray: '#7F7F7F',
40+
lightgrey: '#D2D2D2'
41+
};
42+
2143
// store the reverse mapping
2244
var colorCodesToHtmlNames = {};
2345
var htmlNames = Object.keys(htmlNamesToColorCodes);
2446
htmlNames.forEach(function(htmlName) {
2547
htmlNamesToColorCodes[htmlName].forEach(function(colorCode) {
26-
colorCodesToHtmlNames[colorCode] = htmlName;
48+
colorCodesToHtmlNames[colorCode] = htmlNamesToHex[htmlName];
2749
});
2850
});
2951

spec/integ/irc-to-matrix.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ describe("IRC-to-Matrix message bridging", function() {
180180
"this is a \u0002\u001f\u000303mix of all three";
181181
var tHtmlCloseTags = "</b></u></font>"; // any order allowed
182182
var tHtmlMain = "This text is <b>bold</b> and this is <u>underlined</u> " +
183-
'and this is <font color="green">green</font>. Finally, ' +
184-
'this is a <b><u><font color="green">mix of all three';
183+
'and this is <font color="#009300">green</font>. Finally, ' +
184+
'this is a <b><u><font color="#009300">mix of all three';
185185
var tFallback = "This text is bold and this is underlined and this is " +
186186
"green. Finally, this is a mix of all three";
187187
sdk.sendEvent.and.callFake(function(roomId, type, content) {
@@ -242,8 +242,8 @@ describe("IRC-to-Matrix message bridging", function() {
242242
"org.matrix.custom.html", function(done) {
243243
// $& = Inserts the matched substring.
244244
var tIrcFormattedText = "\u000303$& \u000304 world\u000303 ! \u000304";
245-
var tHtmlMain = '<font color="green">$&amp; </font><font color="red"> world'+
246-
'</font><font color="green"> ! </font>';
245+
var tHtmlMain = '<font color="#009300">$&amp; </font><font color="#FF0000"> world' +
246+
'</font><font color="#009300"> ! </font>';
247247
var tFallback = "$& world ! ";
248248
sdk.sendEvent.and.callFake(function(roomId, type, content) {
249249
expect(roomId).toEqual(roomMapping.roomId);

0 commit comments

Comments
 (0)