diff --git a/public/javascripts/app/helpers/text_formatter.js b/public/javascripts/app/helpers/text_formatter.js index d977414f3..51bc72b4a 100644 --- a/public/javascripts/app/helpers/text_formatter.js +++ b/public/javascripts/app/helpers/text_formatter.js @@ -12,6 +12,11 @@ textFormatter.markdownify = function markdownify(text){ var converter = Markdown.getSanitizingConverter(); + + converter.hooks.chain("postConversion", function (text) { + return text.replace(/(\"(?:(?:http|https):\/\/)?[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(?:\/\S*)?\")(\>)/g, '$1 target="_blank">') + }); + return converter.makeHtml(text) }; diff --git a/spec/javascripts/app/helpers/text_formatter_spec.js b/spec/javascripts/app/helpers/text_formatter_spec.js index 6d408c130..375130147 100644 --- a/spec/javascripts/app/helpers/text_formatter_spec.js +++ b/spec/javascripts/app/helpers/text_formatter_spec.js @@ -40,7 +40,9 @@ describe("app.helpers.textFormatter", function(){ var wrapper = $("
").html(formattedText); _.each(links, function(link) { - expect(wrapper.find("a[href='" + link + "']").text()).toContain(link) + var linkElement = wrapper.find("a[href='" + link + "']"); + expect(linkElement.text()).toContain(link); + expect(linkElement.attr("target")).toContain("_blank"); }) }) })