diff --git a/omeroweb/webclient/static/webclient/javascript/ome.webclient.actions.js b/omeroweb/webclient/static/webclient/javascript/ome.webclient.actions.js index 0bd7a36f40..622f46d645 100644 --- a/omeroweb/webclient/static/webclient/javascript/ome.webclient.actions.js +++ b/omeroweb/webclient/static/webclient/javascript/ome.webclient.actions.js @@ -61,8 +61,30 @@ OME.getURLParameter = function(key) { }; var linkify = function(input) { - var regex = /(https?|ftp|file):\/\/[-a-zA-Z0-9+&@#/%?=~_{}[\]|!:,.;$]*[-a-zA-Z0-9+&@#/%=~_{}[\]|$]/g; - input = input.replace(regex, "$&"); + // Define the regex to check for the specific OMERO HTML-escaped anchor tag format + // input user: Test + // OMERO HTML-escaped input: <a href="https://example.com">Test</a> + const anchorCheckRegex = /^<a\s+href=([^&]+)>([^&]+)<\/a>$/; + + + if(!anchorCheckRegex.test(input)){ + var regex = /(https?|ftp|file):\/\/[-a-zA-Z0-9+&@#/%?=~_{}[\]|!:,.;$]*[-a-zA-Z0-9+&@#/%=~_{}[\]|$]/g; + input = input.replace(regex, "$&"); + }else{ // given input is a html tag + // unescape HTML entities of tag + input= input.replace(/</g, '<') + .replace(/>/g, '>') + .replace(/&/g, '&') + .replace(/"/g, '"') + .replace(/'/g, "'"); + + // Use regex to match and transform the tag + const anchorRegex = /(.*?)<\/a>/i; + + // add target="_blank" + input = input.replace(anchorRegex, "$2"); + } + return linkObjects(input); }; var linkObjects = function(input) {