|
@ -4,24 +4,31 @@ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*eslint max-len:0*/ |
|
|
/*eslint max-len:0*/ |
|
|
var EMAIL_RE = /^<([a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*)>/; |
|
|
var EMAIL_RE = /^([a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*)$/; |
|
|
var AUTOLINK_RE = /^<([a-zA-Z][a-zA-Z0-9+.\-]{1,31}):([^<>\x00-\x20]*)>/; |
|
|
var AUTOLINK_RE = /^([a-zA-Z][a-zA-Z0-9+.\-]{1,31}):([^<>\x00-\x20]*)$/; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = function autolink(state, silent) { |
|
|
module.exports = function autolink(state, silent) { |
|
|
var tail, linkMatch, emailMatch, url, fullUrl, token, |
|
|
var url, fullUrl, token, ch, start, max, |
|
|
pos = state.pos; |
|
|
pos = state.pos; |
|
|
|
|
|
|
|
|
if (state.src.charCodeAt(pos) !== 0x3C/* < */) { return false; } |
|
|
if (state.src.charCodeAt(pos) !== 0x3C/* < */) { return false; } |
|
|
|
|
|
|
|
|
tail = state.src.slice(pos); |
|
|
start = state.pos; |
|
|
|
|
|
max = state.posMax; |
|
|
|
|
|
|
|
|
if (tail.indexOf('>') < 0) { return false; } |
|
|
for (;;) { |
|
|
|
|
|
if (++pos >= max) return false; |
|
|
|
|
|
|
|
|
if (AUTOLINK_RE.test(tail)) { |
|
|
ch = state.src.charCodeAt(pos); |
|
|
linkMatch = tail.match(AUTOLINK_RE); |
|
|
|
|
|
|
|
|
|
|
|
url = linkMatch[0].slice(1, -1); |
|
|
if (ch === 0x3C /* < */) return false; |
|
|
|
|
|
if (ch === 0x3E /* > */) break; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
url = state.src.slice(start + 1, pos); |
|
|
|
|
|
|
|
|
|
|
|
if (AUTOLINK_RE.test(url)) { |
|
|
fullUrl = state.md.normalizeLink(url); |
|
|
fullUrl = state.md.normalizeLink(url); |
|
|
if (!state.md.validateLink(fullUrl)) { return false; } |
|
|
if (!state.md.validateLink(fullUrl)) { return false; } |
|
|
|
|
|
|
|
@ -39,14 +46,11 @@ module.exports = function autolink(state, silent) { |
|
|
token.info = 'auto'; |
|
|
token.info = 'auto'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
state.pos += linkMatch[0].length; |
|
|
state.pos += url.length + 2; |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (EMAIL_RE.test(tail)) { |
|
|
if (EMAIL_RE.test(url)) { |
|
|
emailMatch = tail.match(EMAIL_RE); |
|
|
|
|
|
|
|
|
|
|
|
url = emailMatch[0].slice(1, -1); |
|
|
|
|
|
fullUrl = state.md.normalizeLink('mailto:' + url); |
|
|
fullUrl = state.md.normalizeLink('mailto:' + url); |
|
|
if (!state.md.validateLink(fullUrl)) { return false; } |
|
|
if (!state.md.validateLink(fullUrl)) { return false; } |
|
|
|
|
|
|
|
@ -64,7 +68,7 @@ module.exports = function autolink(state, silent) { |
|
|
token.info = 'auto'; |
|
|
token.info = 'auto'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
state.pos += emailMatch[0].length; |
|
|
state.pos += url.length + 2; |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|