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 1/5] 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 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 2/5] 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 3/5] 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 4/5] 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 5/5] 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} <>
+ -->