From 2b4ca93cf975428b706b8c7f257c9b120dcc3e37 Mon Sep 17 00:00:00 2001 From: Robert Scullin Date: Fri, 12 Apr 2019 22:59:22 -0400 Subject: [PATCH 01/16] Don't linkify hostnames in join/part messages. --- index.html | 3 ++- js/filters.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 3222cd5..f1db8da 100644 --- a/index.html +++ b/index.html @@ -336,7 +336,8 @@ npm run build-electron-{windows, darwin, linux} <>
+ --> + diff --git a/js/filters.js b/js/filters.js index 027acbe..272f61a 100644 --- a/js/filters.js +++ b/js/filters.js @@ -59,6 +59,17 @@ weechat.filter('inlinecolour', function() { }; }); +// Calls the 'linky' filter unless the disable flag is set. Useful for things like join/quit messages, +// so you don't accidentally click a mailto: on someone's hostmask. +weechat.filter('conditionalLinkify', ['$filter', function($filter) { + return function(text, disable) { + if (!text || disable) { + return text; + } + return $filter('linky')(text, '_blank', {rel:'noopener noreferrer'}); + }; +}]); + // apply a filter to an HTML string's text nodes, and do so with not exceedingly terrible performance weechat.filter('DOMfilter', ['$filter', '$sce', function($filter, $sce) { // To prevent nested anchors, we need to know if a filter is going to create them. From 37ff42ee3652457195f26f2d4971c2d52dc59241 Mon Sep 17 00:00:00 2001 From: Robert Scullin Date: Mon, 15 Apr 2019 22:22:01 -0400 Subject: [PATCH 02/16] Removed accidental debugging line. --- index.html | 1 - 1 file changed, 1 deletion(-) diff --git a/index.html b/index.html index f1db8da..17d51a0 100644 --- a/index.html +++ b/index.html @@ -337,7 +337,6 @@ npm run build-electron-{windows, darwin, linux} -->
- From 29c6cc1e8269e5847f62db61a0ced152152fe649 Mon Sep 17 00:00:00 2001 From: Serafeim Papastefanos Date: Wed, 3 Jul 2019 10:01:05 +0300 Subject: [PATCH 03/16] Add a simple codify filter --- index.html | 2 +- js/filters.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 17d51a0..bd587f5 100644 --- a/index.html +++ b/index.html @@ -336,7 +336,7 @@ npm run build-electron-{windows, darwin, linux} <>
+ --> diff --git a/js/filters.js b/js/filters.js index 272f61a..d261c09 100644 --- a/js/filters.js +++ b/js/filters.js @@ -237,4 +237,15 @@ 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) + ''; + return rr; + }) + }; +}); + })(); From aaa49b7f5bb2894d6c33888bdd06b3f4b8f36a7d Mon Sep 17 00:00:00 2001 From: Serafeim Papastefanos Date: Wed, 3 Jul 2019 10:11:18 +0300 Subject: [PATCH 04/16] Add test for codify filter --- test/unit/filters.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/unit/filters.js b/test/unit/filters.js index 2b1358f..74c402d 100644 --- a/test/unit/filters.js +++ b/test/unit/filters.js @@ -92,4 +92,28 @@ describe('Filters', function() { // I.e. if we ever got this far, the bug is fixed. })); }); + + describe('codify', function() { + it('should not mess up text', inject(function(codifyFilter) { + expect(codifyFilter('foo')).toEqual('foo'); + })); + + it('should codify single snippets', inject(function(codifyFilter) { + 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'); + })); + + it('should not codify empty snippets', inject(function(codifyFilter) { + expect(codifyFilter('``')).toEqual('``'); + })); + + it('should not codify single backticks', inject(function(codifyFilter) { + expect(codifyFilter('foo`bar')).toEqual('foo`bar'); + })); + + + }); }); From 8067e3973e4bd58f245de836056eba98d83c2258 Mon Sep 17 00:00:00 2001 From: Serafeim Papastefanos Date: Wed, 3 Jul 2019 10:20:14 +0300 Subject: [PATCH 05/16] Fix linting errors --- js/filters.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/filters.js b/js/filters.js index d261c09..8383769 100644 --- a/js/filters.js +++ b/js/filters.js @@ -239,12 +239,12 @@ weechat.filter('prefixlimit', function() { weechat.filter('codify', function() { return function(text) { - var re = /(`[^``]+`)/g + var re = /(`[^``]+`)/g; return text.replace(re, function(z) { var rr = '' + z.slice(1, z.length-1) + ''; return rr; - }) + }); }; }); From 9ff05110cb3c47d61c7a0455f808e18a72b14786 Mon Sep 17 00:00:00 2001 From: Serafeim Papastefanos Date: Wed, 3 Jul 2019 13:56:46 +0300 Subject: [PATCH 06/16] Improve inline code disply for multiline text... By removing y-padding --- css/glowingbear.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/css/glowingbear.css b/css/glowingbear.css index bee10d0..65a89b8 100644 --- a/css/glowingbear.css +++ b/css/glowingbear.css @@ -926,3 +926,7 @@ img.emojione { [ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak { display: none !important; } + +code { + padding: 0px 2px; +} \ No newline at end of file From 98cebb5b33d94294fc555ce8e4b07f8f41d2c76d Mon Sep 17 00:00:00 2001 From: Serafeim Papastefanos Date: Thu, 4 Jul 2019 08:45:13 +0300 Subject: [PATCH 07/16] Improve behavior with links --- index.html | 2 +- js/filters.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index bd587f5..92c7594 100644 --- a/index.html +++ b/index.html @@ -336,7 +336,7 @@ npm run build-electron-{windows, darwin, linux} <>
+ --> diff --git a/js/filters.js b/js/filters.js index 8383769..9e5db35 100644 --- a/js/filters.js +++ b/js/filters.js @@ -239,8 +239,7 @@ weechat.filter('prefixlimit', function() { weechat.filter('codify', function() { return function(text) { - var re = /(`[^``]+`)/g; - + var re = /(`.+?`)/g; return text.replace(re, function(z) { var rr = '' + z.slice(1, z.length-1) + ''; return rr; From 17175875870bd7e621dd6d3882d037d0832d37ad Mon Sep 17 00:00:00 2001 From: Serafeim Papastefanos Date: Thu, 4 Jul 2019 14:10:41 +0300 Subject: [PATCH 08/16] 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 09/16] 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 10/16] 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; }); }; From fd40cc1593d5f860b0ec8e0de9975808e421f831 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Mon, 19 Aug 2019 13:16:14 +0200 Subject: [PATCH 11/16] codify: only match if preceded by whitespace (or at the start of the line). Fixes #1058 --- js/filters.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/js/filters.js b/js/filters.js index ffbe35f..509503e 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(match, code) { - var rr = '`' + code + '`'; + var re = /(^|\s)`(.+?)`/g; + return text.replace(re, function(match, ws, code) { + var rr = ws + '`' + code + '`'; return rr; }); }; From f01fea605e71fd7385fed03af8a887d59257d4b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Mon, 19 Aug 2019 13:26:00 +0200 Subject: [PATCH 12/16] Update node dependencies npm audit asked me to do it --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c700811..77c3099 100644 --- a/package.json +++ b/package.json @@ -7,12 +7,12 @@ "main": "electron-main.js", "license": "GPLv3", "devDependencies": { - "bower": "^1.8", + "bower": "^1.8.8", "electron-packager": "^12.2.0", "http-server": "^0.11", "jasmine-core": "^3.1", "jshint": "^2.9.6", - "karma": "^3.1.1", + "karma": "^4.2.0", "karma-jasmine": "~1.1", "karma-junit-reporter": "^1.2", "karma-phantomjs-launcher": "^1.0.0", From f10a97659dd1edd03b1ff306406cb0a630b091eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Mon, 19 Aug 2019 13:18:59 +0200 Subject: [PATCH 13/16] codify: also match triple backticks fixes issues with people using ```large code-blocks inline``` --- js/filters.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/js/filters.js b/js/filters.js index 509503e..61f13c0 100644 --- a/js/filters.js +++ b/js/filters.js @@ -239,9 +239,14 @@ weechat.filter('prefixlimit', function() { weechat.filter('codify', function() { return function(text) { - var re = /(^|\s)`(.+?)`/g; - return text.replace(re, function(match, ws, code) { - var rr = ws + '`' + code + '`'; + // The groups of this regex are: + // 1. Start of line or space, to prevent codifying weird`stuff` like this + // 2. Opening single or triple backticks (not 2, not more than 3) + // 3. The code block, does not start with another backtick, non-greedy expansion + // 4. The closing backticks, identical to group 2 + var re = /(^|\s)(```|`)([^`].*?)\2/g; + return text.replace(re, function(match, ws, open, code) { + var rr = ws + '' + open + '' + code + '' + open + ''; return rr; }); }; From 49fac6440dba00a39d21d48083027566a4919643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Mon, 19 Aug 2019 13:58:42 +0200 Subject: [PATCH 14/16] codify: add more tests --- test/unit/filters.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/unit/filters.js b/test/unit/filters.js index 404fc57..ebd6e39 100644 --- a/test/unit/filters.js +++ b/test/unit/filters.js @@ -100,6 +100,8 @@ describe('Filters', function() { it('should codify single snippets', inject(function(codifyFilter) { expect(codifyFilter('z `foo` z')).toEqual('z `foo` z'); + expect(codifyFilter('z `a` z')).toEqual('z `a` z'); + expect(codifyFilter('z ```foo``` z')).toEqual('z ```foo``` z'); })); it('should codify multiple snippets', inject(function(codifyFilter) { @@ -114,6 +116,21 @@ describe('Filters', function() { expect(codifyFilter('foo`bar')).toEqual('foo`bar'); })); + + it('should not codify double backticks', inject(function(codifyFilter) { + expect(codifyFilter('some ``non-code``')).toEqual('some ``non-code``'); + })); + + + it('should not codify pseudo-fancy quotes', inject(function(codifyFilter) { + expect(codifyFilter('some ``fancy qoutes\'\'')).toEqual('some ``fancy qoutes\'\''); + })); + + it('should not codify stuff in the middle of a word or URL', inject(function(codifyFilter) { + expect(codifyFilter('https://foo.bar/`wat`')).toEqual('https://foo.bar/`wat`'); + expect(codifyFilter('Weird`ness`')).toEqual('Weird`ness`'); + })); + }); }); From ac6dca959d7421682629f5550cccad69c9484b03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Mon, 19 Aug 2019 14:00:38 +0200 Subject: [PATCH 15/16] Theme code elements in dark theme --- css/themes/dark.css | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/css/themes/dark.css b/css/themes/dark.css index c03e47a..da260c8 100644 --- a/css/themes/dark.css +++ b/css/themes/dark.css @@ -2114,6 +2114,11 @@ button.close:hover { font-weight: bold; } +code { + background-color: #444; + color: #fff; +} + /* */ /* Mobile layout */ /* */ From 5110061aed43c062d68e6ee73aa1d8c623c0ac28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Tue, 20 Aug 2019 13:50:47 +0200 Subject: [PATCH 16/16] codify: use DOMfilter to avoid breaking URLs This causes code blocks containing URLs to not be codified, but I think that's preferable to the broken behaviour up until now --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 92c7594..3e6ba8f 100644 --- a/index.html +++ b/index.html @@ -336,7 +336,7 @@ npm run build-electron-{windows, darwin, linux} <>
+ -->