Add missing http:// to urls

This commit is contained in:
Steffen van Bergerem 2015-03-09 01:29:16 +01:00
parent 679eca6f03
commit 3298373a7f
2 changed files with 6 additions and 0 deletions

View file

@ -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";
});

View file

@ -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));