mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
f4cb29e05a
Conflicts: dist/showdown.js dist/showdown.js.map dist/showdown.min.js dist/showdown.min.js.map src/converter.js src/subParsers/blockGamut.js src/subParsers/codeSpans.js
30 lines
1.2 KiB
JavaScript
30 lines
1.2 KiB
JavaScript
showdown.subParser('autoLinks', function (text, options, globals) {
|
|
'use strict';
|
|
|
|
text = globals.converter._dispatch('autoLinks.before', text, options);
|
|
|
|
var simpleURLRegex = /\b(((https?|ftp|dict):\/\/|www\.)[^'">\s]+\.[^'">\s]+)(?=\s|$)(?!["<>])/gi,
|
|
delimUrlRegex = /<(((https?|ftp|dict):\/\/|www\.)[^'">\s]+)>/gi,
|
|
simpleMailRegex = /(?:^|[ \n\t])([A-Za-z0-9!#$%&'*+-/=?^_`\{|}~\.]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)(?:$|[ \n\t])/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,
|
|
// Email addresses: <address@domain.foo>
|
|
|
|
if (options.simplifiedAutoLink) {
|
|
text = text.replace(simpleURLRegex, '<a href=\"$1\">$1</a>');
|
|
text = text.replace(simpleMailRegex, replaceMail);
|
|
}
|
|
|
|
function replaceMail(wholeMatch, m1) {
|
|
var unescapedStr = showdown.subParser('unescapeSpecialChars')(m1);
|
|
return showdown.subParser('encodeEmailAddress')(unescapedStr);
|
|
}
|
|
|
|
text = globals.converter._dispatch('autoLinks.after', text, options);
|
|
|
|
return text;
|
|
});
|