autoLinks.js 682 B

1234567891011121314151617181920212223242526272829303132
  1. /**
  2. * Created by Estevao on 12-01-2015.
  3. */
  4. showdown.subParser('autoLinks', function (text) {
  5. 'use strict';
  6. text = text.replace(/<((https?|ftp|dict):[^'">\s]+)>/gi, '<a href=\"$1\">$1</a>');
  7. // Email addresses: <address@domain.foo>
  8. /*
  9. text = text.replace(/
  10. <
  11. (?:mailto:)?
  12. (
  13. [-.\w]+
  14. \@
  15. [-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+
  16. )
  17. >
  18. /gi);
  19. */
  20. var pattern = /<(?:mailto:)?([-.\w]+\@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi;
  21. text = text.replace(pattern, function (wholeMatch, m1) {
  22. var unescapedStr = showdown.subParser('unescapeSpecialChars')(m1);
  23. return showdown.subParser('encodeEmailAddress')(unescapedStr);
  24. });
  25. return text;
  26. });