2015-07-11 09:42:53 +08:00
|
|
|
showdown.subParser('autoLinks', function (text, options) {
|
2015-01-19 19:37:21 +08:00
|
|
|
'use strict';
|
2015-01-16 05:21:33 +08:00
|
|
|
|
2015-07-11 09:42:53 +08:00
|
|
|
//simpleURLRegex = /\b(((https?|ftp|dict):\/\/|www\.)[-.+~:?#@!$&'()*,;=[\]\w]+)\b/gi,
|
2015-01-16 05:21:33 +08:00
|
|
|
|
2015-07-11 09:42:53 +08:00
|
|
|
var simpleURLRegex = /\b(((https?|ftp|dict):\/\/|www\.)[^'">\s]+\.[^'">\s]+)(?=\s|$)(?!["<>])/gi,
|
|
|
|
delimUrlRegex = /<(((https?|ftp|dict):\/\/|www\.)[^'">\s]+)>/gi,
|
|
|
|
simpleMailRegex = /\b(?:mailto:)?([-.\w]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)\b/gi,
|
|
|
|
delimMailRegex = /<(?:mailto:)?([-.\w]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi;
|
|
|
|
|
|
|
|
text = text.replace(delimUrlRegex, '<a href=\"$1\">$1</a>');
|
|
|
|
text = text.replace(delimMailRegex, replaceMail);
|
|
|
|
//simpleURLRegex = /\b(((https?|ftp|dict):\/\/|www\.)[-.+~:?#@!$&'()*,;=[\]\w]+)\b/gi,
|
2015-01-19 19:37:21 +08:00
|
|
|
// Email addresses: <address@domain.foo>
|
2015-01-16 05:21:33 +08:00
|
|
|
|
2015-07-11 09:42:53 +08:00
|
|
|
if (options.simplifiedAutoLink) {
|
|
|
|
text = text.replace(simpleURLRegex, '<a href=\"$1\">$1</a>');
|
2015-08-11 12:57:52 +08:00
|
|
|
text = text.replace(simpleMailRegex, replaceMail);
|
2015-07-11 09:42:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function replaceMail(wholeMatch, m1) {
|
2015-01-19 19:37:21 +08:00
|
|
|
var unescapedStr = showdown.subParser('unescapeSpecialChars')(m1);
|
|
|
|
return showdown.subParser('encodeEmailAddress')(unescapedStr);
|
2015-07-11 09:42:53 +08:00
|
|
|
}
|
2015-01-16 05:21:33 +08:00
|
|
|
|
2015-01-19 19:37:21 +08:00
|
|
|
return text;
|
2015-01-16 05:21:33 +08:00
|
|
|
});
|