|
|
@ -21,15 +21,25 @@ var autolinker = new Autolinker({ |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
function isLinkOpen(str) { |
|
|
|
return /^<a[>\s]/i.test(str); |
|
|
|
} |
|
|
|
function isLinkClose(str) { |
|
|
|
return /^<\/a\s*>/i.test(str); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
module.exports = function linkify(t, state) { |
|
|
|
var i, token, text, nodes, ln, pos, level, |
|
|
|
htmlLinkLevel = 0, |
|
|
|
tokens = state.tokens; |
|
|
|
|
|
|
|
// We scan from the end, to keep position when new tags added.
|
|
|
|
// Use reversed logic in links start/end match
|
|
|
|
for (i = tokens.length - 1; i >= 0; i--) { |
|
|
|
token = tokens[i]; |
|
|
|
|
|
|
|
// Skip content of links
|
|
|
|
// Skip content of markdown links
|
|
|
|
if (token.type === 'link_close') { |
|
|
|
i--; |
|
|
|
while (tokens[i].type !== 'link_open' && tokens[i].level !== token.level) { |
|
|
@ -39,6 +49,17 @@ module.exports = function linkify(t, state) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
// Skip content of html tag links
|
|
|
|
if (token.type === 'htmltag') { |
|
|
|
if (isLinkOpen(token.content) && htmlLinkLevel > 0) { |
|
|
|
htmlLinkLevel--; |
|
|
|
} |
|
|
|
if (isLinkClose(token.content)) { |
|
|
|
htmlLinkLevel++; |
|
|
|
} |
|
|
|
} |
|
|
|
if (htmlLinkLevel > 0) { continue; } |
|
|
|
|
|
|
|
if (token.type === 'text' && |
|
|
|
(token.content.indexOf('://') || |
|
|
|
token.content.indexOf('www'))) { |
|
|
|