From 17175875870bd7e621dd6d3882d037d0832d37ad Mon Sep 17 00:00:00 2001 From: Serafeim Papastefanos Date: Thu, 4 Jul 2019 14:10:41 +0300 Subject: [PATCH 1/3] Small codify improvements --- css/glowingbear.css | 2 ++ js/filters.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/css/glowingbear.css b/css/glowingbear.css index 65a89b8..ca11870 100644 --- a/css/glowingbear.css +++ b/css/glowingbear.css @@ -929,4 +929,6 @@ img.emojione { code { padding: 0px 2px; + color: #444; + border: 1pt solid #444; } \ No newline at end of file diff --git a/js/filters.js b/js/filters.js index 9e5db35..a1334a7 100644 --- a/js/filters.js +++ b/js/filters.js @@ -241,7 +241,7 @@ weechat.filter('codify', function() { return function(text) { var re = /(`.+?`)/g; return text.replace(re, function(z) { - var rr = '' + z.slice(1, z.length-1) + ''; + var rr = '`' + z.slice(1, z.length-1) + '`'; return rr; }); }; From 2470192cf021fe830110d96b0f355737df81d283 Mon Sep 17 00:00:00 2001 From: Serafeim Papastefanos Date: Thu, 4 Jul 2019 14:26:06 +0300 Subject: [PATCH 2/3] Fix tests for codify --- test/unit/filters.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/filters.js b/test/unit/filters.js index 74c402d..404fc57 100644 --- a/test/unit/filters.js +++ b/test/unit/filters.js @@ -99,11 +99,11 @@ describe('Filters', function() { })); it('should codify single snippets', inject(function(codifyFilter) { - expect(codifyFilter('z `foo` z')).toEqual('z foo z'); + expect(codifyFilter('z `foo` z')).toEqual('z `foo` z'); })); it('should codify multiple snippets', inject(function(codifyFilter) { - expect(codifyFilter('z `foo` z `bar` `baz`')).toEqual('z foo z bar baz'); + expect(codifyFilter('z `foo` z `bar` `baz`')).toEqual('z `foo` z `bar` `baz`'); })); it('should not codify empty snippets', inject(function(codifyFilter) { From 94ad3b8b51d3e7ff7e0a5df91bcae5d10bac98db Mon Sep 17 00:00:00 2001 From: Serafeim Papastefanos Date: Thu, 4 Jul 2019 14:44:34 +0300 Subject: [PATCH 3/3] Improve regex to avoid slicing --- js/filters.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/js/filters.js b/js/filters.js index a1334a7..ffbe35f 100644 --- a/js/filters.js +++ b/js/filters.js @@ -239,9 +239,9 @@ weechat.filter('prefixlimit', function() { weechat.filter('codify', function() { return function(text) { - var re = /(`.+?`)/g; - return text.replace(re, function(z) { - var rr = '`' + z.slice(1, z.length-1) + '`'; + var re = /`(.+?)`/g; + return text.replace(re, function(match, code) { + var rr = '`' + code + '`'; return rr; }); };