Skip to content

Commit 833b3ae

Browse files
committed
fix autolink
1 parent f67fa41 commit 833b3ae

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

Parser.js

Lines changed: 4 additions & 4 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.16",
10+
"version": "2.4.17",
1111
"scripts": {
1212
"test": "mocha",
1313
"build": "cake build"

src/Parser.coffee

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,9 @@ class Parser
333333

334334
# autolink url
335335
if enableAutoLink
336-
text = text.replace /(^|[^\"])((https?):\S+)($|[^\"])/ig, (matches...) =>
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...) =>
337337
link = @call 'parseLink', matches[2]
338-
"#{matches[1]}<a href=\"#{matches[2]}\">#{link}</a>#{matches[4]}"
338+
"#{matches[1]}<a href=\"#{matches[2]}\">#{link}</a>#{matches[5]}"
339339

340340
text = @call 'afterParseInlineBeforeRelease', text
341341
text = @releaseHolder text, clearHolders
@@ -988,9 +988,9 @@ class Parser
988988

989989

990990
cleanUrl: (url) ->
991-
if !!(matches = url.match /^\s*((http|https|ftp|mailto):\S+)/i)
991+
if !!(matches = url.match /^\s*(https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&\/=]*))/)
992992
matches[1]
993-
else if !!(matches = url.match /^\s*(\S+)/)
993+
else if !!(matches = url.match /^\s*([-a-zA-Z0-9()@:%_\+.~#?&\/=]+)/)
994994
matches[1]
995995
else
996996
'#'

0 commit comments

Comments
 (0)