Comparing version 1.11.1 to 1.11.2
@@ -43,4 +43,4 @@ var Mehdown; | ||
text = text.replace(Mehdown.urlRegExp, function() { | ||
var domain = arguments[1]; | ||
var href = (domain.indexOf('http') < 0) ? 'http://' + domain : domain; | ||
var url = arguments[1]; | ||
var href = (url.indexOf('http') < 0) ? 'http://' + url : url; | ||
var preceding = text.substring(0, arguments[2]); | ||
@@ -50,5 +50,5 @@ var insideTagAttrRegex = /<(?!\/)[^>]+(?!>)$/g; | ||
// use the correct protocol if domain is baseUrl domain | ||
if (href !== Mehdown.baseUrl && href.split('/')[2] === Mehdown.baseUrl.split('/')[2]) { | ||
href = Mehdown.baseUrl.split('://')[0] + '://' + domain; | ||
// use the correct protocol if href contains baseUrl domain | ||
if (href.split('/')[2] === Mehdown.baseUrl.split('/')[2] && href.split(':')[0] !== Mehdown.baseUrl.split(':')[0]) { | ||
href = Mehdown.baseUrl.split('://')[0] + '://' + href.replace(/^https?:\/\//, ''); | ||
} | ||
@@ -58,22 +58,34 @@ | ||
if (preceding.match(insideTagAttrRegex) || preceding.match(insideAnchorTagRegex)) { | ||
return domain; | ||
return url; | ||
} | ||
// don't use http protocol on email adresses | ||
if (domain.indexOf('@') >= 0) { | ||
var parts = domain.split('@'); | ||
if (parts[1].match(Mehdown.urlRegExp)) { | ||
href = 'mailto:' + domain; | ||
if (url.indexOf('@') >= 0 && !url.split('@')[0].match(Mehdown.urlRegExp)) { | ||
if (url.split('@')[1].match(Mehdown.urlRegExp)) { | ||
href = 'mailto:' + url; | ||
} else { | ||
// this is a wierd something@something-no-tld that the regex thinks is a url, abort | ||
return domain; | ||
// this is a weird something@something-no-tld that the regex thinks is a url, abort | ||
return url; | ||
} | ||
} | ||
return '<a href="' + href + '">' + domain + '</a>'; | ||
return '<a href="' + href + '">' + url + '</a>'; | ||
}); | ||
// Usernames | ||
text = text.replace(Mehdown.usernameRegExp, '$1' + Mehdown.username('$2')); | ||
text = text.replace(Mehdown.usernameRegExp, function() { | ||
var precedingNonWord = arguments[1]; | ||
var username = arguments[2]; | ||
var preceding = text.substring(0, arguments[3]); | ||
var insideTagAttrRegex = /<(?!\/)[^>]+(?!>)$/g; | ||
var insideAnchorTagRegex = /<a[^>]*>.+(?!<\/a>)$/g; | ||
// inside tag attr or anchor tag, abort | ||
if (preceding.match(insideTagAttrRegex) || preceding.match(insideAnchorTagRegex)) { | ||
return precedingNonWord + '@' + username; | ||
} | ||
return precedingNonWord + Mehdown.username(username); | ||
}); | ||
// Imgur GIFV: http://imgur.com/blog/2014/10/09/introducing-gifv/ | ||
@@ -80,0 +92,0 @@ text = text.replace(/<a href="https?:\/\/(?:i\.)?(?:imgur\.com\/)(\w+)\.gifv">https?:\/\/(?:i\.)?(?:imgur\.com\/)(\w+)\.gifv<\/a>/gi, Mehdown.imgurGifv('$1')); |
@@ -13,3 +13,3 @@ { | ||
}, | ||
"version": "1.11.1" | ||
"version": "1.11.2" | ||
} |
@@ -184,2 +184,22 @@ var assert = require('assert'); | ||
}); | ||
it('mediocre.com/@username', function() { | ||
var text = mehdown.parse('mediocre.com/@username'); | ||
assert.equal(text, '<a href="https://mediocre.com/@username">mediocre.com/@username</a>'); | ||
}); | ||
it('http://mediocre.com/@username', function() { | ||
var text = mehdown.parse('http://mediocre.com/@username'); | ||
assert.equal(text, '<a href="https://mediocre.com/@username">http://mediocre.com/@username</a>'); | ||
}); | ||
it('https://mediocre.com/@username', function() { | ||
var text = mehdown.parse('https://mediocre.com/@username'); | ||
assert.equal(text, '<a href="https://mediocre.com/@username">https://mediocre.com/@username</a>'); | ||
}); | ||
it('<a href="https://mediocre.com/@username">@username</a>', function() { | ||
var text = mehdown.parse('<a href="https://mediocre.com/@username">@username</a>'); | ||
assert.equal(text, '<a href="https://mediocre.com/@username">@username</a>'); | ||
}); | ||
}); | ||
@@ -186,0 +206,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39901
420