From a53544b44a5e4c6fe481072a2eb09c2b003db08c Mon Sep 17 00:00:00 2001 From: megawac Date: Sat, 25 Oct 2014 15:02:12 -0400 Subject: [PATCH 1/2] Support MIRC style terminators (^O) --- client/js/libs/handlebars/parse.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/client/js/libs/handlebars/parse.js b/client/js/libs/handlebars/parse.js index 081c69f..2c7bb44 100644 --- a/client/js/libs/handlebars/parse.js +++ b/client/js/libs/handlebars/parse.js @@ -50,6 +50,7 @@ function uri(text) { var regex = { color: /\003([0-9]{1,2})[,]?([0-9]{1,2})?([^\003]+)/, + terminator: /\x0D/, styles: [ [/\002([^\002]+)(\002)?/, ["", ""]], [/\037([^\037]+)(\037)?/, ["", ""]], @@ -59,6 +60,9 @@ function colors(text) { if (!text) { return text; } + if (regex.terminator.test(text)) { + return $.map(text.split(regex.terminator), colors); + } if (regex.color.test(text)) { var match; while (match = regex.color.exec(text)) { From fbe43b3b7af25a290e979f9c8f56ab51e6b53eee Mon Sep 17 00:00:00 2001 From: megawac Date: Sat, 25 Oct 2014 15:07:15 -0400 Subject: [PATCH 2/2] Fix indentation --- client/js/libs/handlebars/parse.js | 64 +++++++++++++++--------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/client/js/libs/handlebars/parse.js b/client/js/libs/handlebars/parse.js index 2c7bb44..d0f0005 100644 --- a/client/js/libs/handlebars/parse.js +++ b/client/js/libs/handlebars/parse.js @@ -50,42 +50,42 @@ function uri(text) { var regex = { color: /\003([0-9]{1,2})[,]?([0-9]{1,2})?([^\003]+)/, - terminator: /\x0D/, + terminator: /\x0D/, styles: [ - [/\002([^\002]+)(\002)?/, ["", ""]], - [/\037([^\037]+)(\037)?/, ["", ""]], - ] + [/\002([^\002]+)(\002)?/, ["", ""]], + [/\037([^\037]+)(\037)?/, ["", ""]], + ] }; function colors(text) { if (!text) { return text; } - if (regex.terminator.test(text)) { - return $.map(text.split(regex.terminator), colors); - } - if (regex.color.test(text)) { - var match; - while (match = regex.color.exec(text)) { - var color = "color-" + match[1]; - var bg = match[2]; - if (bg) { - color += " bg-" + bg; - } - var text = text.replace( - match[0], - "" + match[3] + "" - ); - } - } - for (var i in regex.styles) { - var pattern = regex.styles[i][0]; - var style = regex.styles[i][1]; - if (pattern.test(text)) { - var match; - while (match = pattern.exec(text)) { - text = text.replace(match[0], style[0] + match[1] + style[1]); - } - } - } - return text; + if (regex.terminator.test(text)) { + return $.map(text.split(regex.terminator), colors); + } + if (regex.color.test(text)) { + var match; + while (match = regex.color.exec(text)) { + var color = "color-" + match[1]; + var bg = match[2]; + if (bg) { + color += " bg-" + bg; + } + var text = text.replace( + match[0], + "" + match[3] + "" + ); + } + } + for (var i in regex.styles) { + var pattern = regex.styles[i][0]; + var style = regex.styles[i][1]; + if (pattern.test(text)) { + var match; + while (match = pattern.exec(text)) { + text = text.replace(match[0], style[0] + match[1] + style[1]); + } + } + } + return text; }