@@ -270,9 +270,9 @@ class Parser
270270 @ makeHolder prefix + escaped
271271
272272 # link
273- text = text .replace / <(https? :\/\/ . + )>/ ig , (matches ... ) =>
273+ text = text .replace / <(https? :\/\/ . + | (?:mailto:) ? [_ a-z0-9 - \.\+ ] + @ [_ \w -] + \. [ a-z ] {2,} )>/ ig , (matches ... ) =>
274274 url = @ cleanUrl matches[1 ]
275- link = @ call ' parseLink' , matches[ 1 ]
275+ link = @ call ' parseLink' , url
276276
277277 @ makeHolder " <a href=\" #{ url} \" >#{ link} </a>"
278278
@@ -329,13 +329,13 @@ class Parser
329329
330330 # strong and em and some fuck
331331 text = @ parseInlineCallback text
332- text = text .replace / <([_a-z0-9 -\.\+ ] + @[^ @] + \. [a-z ] {2,} )>/ ig , ' <a href="mailto:$1">$1</a>'
333332
334333 # autolink url
335334 if enableAutoLink
336- text = text .replace / (^ | [^ \" ] )(https? :\/\/ (www\. )? [-a-zA-Z0-9 @:%. _\+ ~#=] {1,256} \. [a-zA-Z0-9 ()] {1,6} \b ([-a-zA-Z0-9 ()@:%_\+ . ~#?&\/ =] * ))($ | [^ \" ] )/ g , (matches ... ) =>
337- link = @ call ' parseLink' , matches[2 ]
338- " #{ matches[1 ]} <a href=\" #{ matches[2 ]} \" >#{ link} </a>#{ matches[5 ]} "
335+ text = text .replace / (^ | [^ \" ] )(https? :\/\/ (www\. )? [-a-zA-Z0-9 @:%. _\+ ~#=] {1,256} \. [a-zA-Z0-9 ()] {1,6} \b ([-a-zA-Z0-9 ()@:%_\+ . ~#?&\/ =] * )| (?:mailto:)? [_a-z0-9 -\.\+ ] + @[_\w -] + \. [a-z ] {2,} )($ | [^ \" ] )/ g , (matches ... ) =>
336+ url = @ cleanUrl matches[2 ]
337+ link = @ call ' parseLink' , url
338+ " #{ matches[1 ]} <a href=\" #{ link} \" >#{ matches[2 ]} </a>#{ matches[5 ]} "
339339
340340 text = @ call ' afterParseInlineBeforeRelease' , text
341341 text = @ releaseHolder text, clearHolders
@@ -990,7 +990,10 @@ class Parser
990990 cleanUrl : (url ) ->
991991 url = url .replace / ["'<>\s ] / g , ' '
992992
993- return ' #' if (url .match / ^ \w + :/ i ) and not (url .match / ^ https? :/ i )
993+ if !! (matches = url .match / ^ (mailto:)? [_a-z0-9 -\.\+ ] + @[_\w -] + \. [a-z ] {2,} $ / i )
994+ url = ' mailto:' + url if not matches[1 ]?
995+
996+ return ' #' if (url .match / ^ \w + :/ i ) and not (url .match / ^ (https? | mailto):/ i )
994997
995998 url
996999
0 commit comments