From 5ff3834b4a8bb05752bd71a87372c4b28f9b7685 Mon Sep 17 00:00:00 2001 From: Joscha Schmiedt <joscha@schmiedt.dev> Date: Wed, 14 Feb 2024 22:29:03 +0100 Subject: [PATCH] Add a better regex for linkify --- src/core/js/ext_cosmetics.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/core/js/ext_cosmetics.js b/src/core/js/ext_cosmetics.js index 5d1ac8ee..aeb88cc9 100644 --- a/src/core/js/ext_cosmetics.js +++ b/src/core/js/ext_cosmetics.js @@ -68,7 +68,10 @@ var cosmetics = new function () { * @returns {string} text with <a> elements instead of raw links */ function linkify_string(text) { - const match_url_regex = /https?:\/\/[^\s]*\b(?![,:;?!])/gi; + // const match_url_regex = /https?:\/\/[^\s]*/g // original + // https://regexr.com helps you design regex + const match_url_regex = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.?[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/g + return text.replace(match_url_regex, function (href) { var link_text = href; if (_link_cut_off_length > 4 && link_text.length > _link_cut_off_length) { -- GitLab