autoLinks.js 1.1 KB

123456789101112131415161718192021222324252627
  1. showdown.subParser('autoLinks', function (text, options) {
  2. 'use strict';
  3. //simpleURLRegex = /\b(((https?|ftp|dict):\/\/|www\.)[-.+~:?#@!$&'()*,;=[\]\w]+)\b/gi,
  4. var simpleURLRegex = /\b(((https?|ftp|dict):\/\/|www\.)[^'">\s]+\.[^'">\s]+)(?=\s|$)(?!["<>])/gi,
  5. delimUrlRegex = /<(((https?|ftp|dict):\/\/|www\.)[^'">\s]+)>/gi,
  6. simpleMailRegex = /\b(?:mailto:)?([-.\w]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)\b/gi,
  7. delimMailRegex = /<(?:mailto:)?([-.\w]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi;
  8. text = text.replace(delimUrlRegex, '<a href=\"$1\">$1</a>');
  9. text = text.replace(delimMailRegex, replaceMail);
  10. //simpleURLRegex = /\b(((https?|ftp|dict):\/\/|www\.)[-.+~:?#@!$&'()*,;=[\]\w]+)\b/gi,
  11. // Email addresses: <address@domain.foo>
  12. if (options.simplifiedAutoLink) {
  13. text = text.replace(simpleURLRegex, '<a href=\"$1\">$1</a>');
  14. text = text.replace(simpleMailRegex, '<a href=\"$1\">$1</a>');
  15. }
  16. function replaceMail(wholeMatch, m1) {
  17. var unescapedStr = showdown.subParser('unescapeSpecialChars')(m1);
  18. return showdown.subParser('encodeEmailAddress')(unescapedStr);
  19. }
  20. return text;
  21. });