-
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.
feat(simplifiedAutoLink): add support for GFM autolinks
Github Flavored Markdown detects urls and mails embeded in the text without any extra markup or delimiter. This commit adds this feature to showdown through an option called "simplifiedAutoLink". Related to #164
- Loading branch information
Showing
12 changed files
with
133 additions
and
53 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
@@ -1,28 +1,27 @@ | ||
showdown.subParser('autoLinks', function (text) { | ||
showdown.subParser('autoLinks', function (text, options) { | ||
'use strict'; | ||
|
||
text = text.replace(/<((https?|ftp|dict):[^'">\s]+)>/gi, '<a href=\"$1\">$1</a>'); | ||
//simpleURLRegex = /\b(((https?|ftp|dict):\/\/|www\.)[-.+~:?#@!$&'()*,;=[\]\w]+)\b/gi, | ||
|
||
var simpleURLRegex = /\b(((https?|ftp|dict):\/\/|www\.)[^'">\s]+\.[^'">\s]+)(?=\s|$)(?!["<>])/gi, | ||
delimUrlRegex = /<(((https?|ftp|dict):\/\/|www\.)[^'">\s]+)>/gi, | ||
simpleMailRegex = /\b(?:mailto:)?([-.\w]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)\b/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(delimMailRegex, replaceMail); | ||
//simpleURLRegex = /\b(((https?|ftp|dict):\/\/|www\.)[-.+~:?#@!$&'()*,;=[\]\w]+)\b/gi, | ||
// Email addresses: <[email protected]> | ||
|
||
/* | ||
text = text.replace(/ | ||
< | ||
(?:mailto:)? | ||
( | ||
[-.\w]+ | ||
\@ | ||
[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+ | ||
) | ||
> | ||
/gi); | ||
*/ | ||
var pattern = /<(?:mailto:)?([-.\w]+\@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi; | ||
text = text.replace(pattern, function (wholeMatch, m1) { | ||
if (options.simplifiedAutoLink) { | ||
text = text.replace(simpleURLRegex, '<a href=\"$1\">$1</a>'); | ||
text = text.replace(simpleMailRegex, '<a href=\"$1\">$1</a>'); | ||
} | ||
|
||
function replaceMail(wholeMatch, m1) { | ||
var unescapedStr = showdown.subParser('unescapeSpecialChars')(m1); | ||
return showdown.subParser('encodeEmailAddress')(unescapedStr); | ||
}); | ||
} | ||
|
||
return text; | ||
|
||
}); |
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,11 @@ | ||
<p>foo.bar</p> | ||
|
||
<p>www.foobar</p> | ||
|
||
<p><a href="www.foobar.com">www.foobar.com</a></p> | ||
|
||
<p><a href="http://foobar.com">http://foobar.com</a></p> | ||
|
||
<p><a href="https://www.foobar.com/baz?bazinga=nhecos;">https://www.foobar.com/baz?bazinga=nhecos;</a></p> | ||
|
||
<p><a href="http://www.google.com/">http://www.google.com</a></p> |
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,11 @@ | ||
foo.bar | ||
|
||
www.foobar | ||
|
||
www.foobar.com | ||
|
||
http://foobar.com | ||
|
||
https://www.foobar.com/baz?bazinga=nhecos; | ||
|
||
<a href="http://www.google.com/">http://www.google.com</a> |
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
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,13 @@ | ||
/** | ||
* Created by Estevao on 10-07-2015. | ||
*/ | ||
/* | ||
var showdown = require('../dist/showdown.js'), | ||
bootstrap = require('./bootstrap.js'), | ||
assertion = bootstrap.assertion, | ||
testsuite = bootstrap.getTestSuite('test/features/'); | ||
describe('makeHtml() single test', function () { | ||
'use strict'; | ||
}); | ||
*/ |