Skip to content

Commit 5de54cc

Browse files
committed
fix mailto
1 parent c1ebb10 commit 5de54cc

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

Parser.js

Lines changed: 14 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
"license": "BSD-4-Clause",
99
"author": "SegmentFault",
10-
"version": "2.4.18",
10+
"version": "2.4.19",
1111
"scripts": {
1212
"test": "mocha",
1313
"build": "cake build"

src/Parser.coffee

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)