Skip to content

Commit

Permalink
fix(simplifiedAutoLink): fix missing spaces before and after email ad…
Browse files Browse the repository at this point in the history
…dresses

Space char before and after the linked email address is no longer dropped
with "simplifiedAutoLink" option enabled.

Closes #330
  • Loading branch information
tivie committed Jan 27, 2017
1 parent 90c52b8 commit 5190b6a
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 11 deletions.
9 changes: 5 additions & 4 deletions dist/showdown.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/showdown.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/showdown.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/showdown.min.js.map

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions src/subParsers/autoLinks.js
Expand Up @@ -6,8 +6,8 @@ showdown.subParser('autoLinks', function (text, options, globals) {
var simpleURLRegex = /\b(((https?|ftp|dict):\/\/|www\.)[^'">\s]+\.[^'">\s]+)()(?=\s|$)(?!["<>])/gi,
simpleURLRegex2 = /\b(((https?|ftp|dict):\/\/|www\.)[^'">\s]+\.[^'">\s]+?)([.!?()]?)(?=\s|$)(?!["<>])/gi,
delimUrlRegex = /<(((https?|ftp|dict):\/\/|www\.)[^'">\s]+)>/gi,
simpleMailRegex = /(?:^|\s)([A-Za-z0-9!#$%&'*+-/=?^_`{|}~.]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)(?:$|\s)/gi,
delimMailRegex = /<(?:mailto:)?([-.\w]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi;
simpleMailRegex = /(^|\s)(?:mailto:)?([A-Za-z0-9!#$%&'*+-/=?^_`{|}~.]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)(?=$|\s)/gmi,
delimMailRegex = /<()(?:mailto:)?([-.\w]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi;

text = text.replace(delimUrlRegex, replaceLink);
text = text.replace(delimMailRegex, replaceMail);
Expand Down Expand Up @@ -35,16 +35,17 @@ showdown.subParser('autoLinks', function (text, options, globals) {
return '<a href="' + link + '">' + lnkTxt + '</a>' + append;
}

function replaceMail(wholeMatch, mail) {
function replaceMail(wholeMatch, b, mail) {
var href = 'mailto:';
b = b || '';
mail = showdown.subParser('unescapeSpecialChars')(mail);
if (options.encodeEmails) {
mail = showdown.helper.encodeEmailAddress(mail);
href = showdown.helper.encodeEmailAddress(href + mail);
} else {
href = href + mail;
}
return '<a href="' + href + '">' + mail + '</a>';
return b + '<a href="' + href + '">' + mail + '</a>';
}

text = globals.converter._dispatch('autoLinks.after', text, options, globals);
Expand Down
@@ -0,0 +1 @@
<p>Just an example <a href="mailto:info@example.com">info@example.com</a> ok?​</p>
@@ -0,0 +1 @@
Just an example info@example.com ok?​
2 changes: 2 additions & 0 deletions test/node/testsuite.features.js
Expand Up @@ -55,6 +55,8 @@ describe('makeHtml() features testsuite', function () {
converter = new showdown.Converter({ghMentions: true});
} else if (testsuite[i].name === 'disable-email-encoding') {
converter = new showdown.Converter({encodeEmails: false});
} else if (testsuite[i].name === '#330.simplifiedAutoLink-drops-character-before-and-after-linked-mail') {
converter = new showdown.Converter({encodeEmails: false, simplifiedAutoLink: true});
} else {
converter = new showdown.Converter();
}
Expand Down

0 comments on commit 5190b6a

Please sign in to comment.