-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(simplifiedAutoLink): fix simplified autolink to match GFM behavior
Using the simplifiedAutoLink option does not return the expected GFM behaviour when parsing links without a http prefix. Previously, `www.google.com` would be parsed into `<a href="www.google.com">www.google.com</a>`. With this fix, showdown behaves like GFM, and the result is `<a href="http://www.google.com">www.google.com</a>` Closes #284, closes #285
- Loading branch information
Showing
10 changed files
with
37 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,16 +8,24 @@ showdown.subParser('autoLinks', function (text, options, globals) { | |
simpleMailRegex = /(?:^|[ \n\t])([A-Za-z0-9!#$%&'*+-/=?^_`\{|}~\.]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)(?:$|[ \n\t])/gi, | ||
delimMailRegex = /<(?:mailto:)?([-.\w]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi; | ||
|
||
text = text.replace(delimUrlRegex, '<a href=\"$1\">$1</a>'); | ||
text = text.replace(delimUrlRegex, replaceLink); | ||
text = text.replace(delimMailRegex, replaceMail); | ||
//simpleURLRegex = /\b(((https?|ftp|dict):\/\/|www\.)[-.+~:?#@!$&'()*,;=[\]\w]+)\b/gi, | ||
// simpleURLRegex = /\b(((https?|ftp|dict):\/\/|www\.)[-.+~:?#@!$&'()*,;=[\]\w]+)\b/gi, | ||
// Email addresses: <[email protected]> | ||
|
||
if (options.simplifiedAutoLink) { | ||
text = text.replace(simpleURLRegex, '<a href=\"$1\">$1</a>'); | ||
text = text.replace(simpleURLRegex, replaceLink); | ||
text = text.replace(simpleMailRegex, replaceMail); | ||
} | ||
|
||
function replaceLink(wm, link) { | ||
var lnkTxt = link; | ||
if (/^www\./i.test(link)) { | ||
link = link.replace(/^www\./i, 'http://www.'); | ||
} | ||
return '<a href="' + link + '">' + lnkTxt + '</a>'; | ||
} | ||
|
||
function replaceMail(wholeMatch, m1) { | ||
var unescapedStr = showdown.subParser('unescapeSpecialChars')(m1); | ||
return showdown.subParser('encodeEmailAddress')(unescapedStr); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
test/features/#284.simplifiedAutoLink-does-not-match-GFM-style.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<p>this is a link to <a href="http://www.github.com">www.github.com</a></p> | ||
|
||
<p>this is a link to <a href="http://www.google.com">www.google.com</a></p> |
3 changes: 3 additions & 0 deletions
3
test/features/#284.simplifiedAutoLink-does-not-match-GFM-style.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
this is a link to www.github.com | ||
|
||
this is a link to <www.google.com> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0cc55b0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! 🎉