diff --git a/app/assets/javascripts/app/helpers/text_formatter.js b/app/assets/javascripts/app/helpers/text_formatter.js index a3733b629b40ee0993c6d1946ce3b98eaec1e5d8..a6fc1c391bfca15c54fa2133a21abb33c0cc198b 100644 --- a/app/assets/javascripts/app/helpers/text_formatter.js +++ b/app/assets/javascripts/app/helpers/text_formatter.js @@ -42,6 +42,7 @@ }); md.use(inlinePlugin, 'link_new_window_and_punycode', 'link_open', function (tokens, idx) { + tokens[idx].href = tokens[idx].href.replace(/^www\./, "http://www."); tokens[idx].href = punycodeURL(tokens[idx].href); tokens[idx].target = "_blank"; }); diff --git a/spec/javascripts/app/helpers/text_formatter_spec.js b/spec/javascripts/app/helpers/text_formatter_spec.js index 0343dc4edf95ad5fd817d31616686b007d646b49..cbdfbe6ac6a9b638576884969e825080b831c672 100644 --- a/spec/javascripts/app/helpers/text_formatter_spec.js +++ b/spec/javascripts/app/helpers/text_formatter_spec.js @@ -116,6 +116,11 @@ describe("app.helpers.textFormatter", function(){ expect(this.formatter('<http://google.com>')).toContain('_blank'); }); + it("adds a missing http://", function() { + expect(this.formatter('[test](www.google.com)')).toContain('href="http://www.google.com"'); + expect(this.formatter('[test](http://www.google.com)')).toContain('href="http://www.google.com"'); + }); + it("respects code blocks", function() { var content = '`<unknown tag>`'; var wrapper = $('<div>').html(this.formatter(content));