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] 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; }); };