fix(simplifiedAutoLink): fix missing spaces before and after email addresses

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

Closes #330
This commit is contained in:
Estevao Soares dos Santos 2017-01-27 19:25:46 +00:00
parent 90c52b83e7
commit 5190b6a41f
8 changed files with 9 additions and 4 deletions

BIN
dist/showdown.js vendored

Binary file not shown.

BIN
dist/showdown.js.map vendored

Binary file not shown.

BIN
dist/showdown.min.js vendored

Binary file not shown.

Binary file not shown.

View File

@ -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);
@ -35,8 +35,9 @@ 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);
@ -44,7 +45,7 @@ showdown.subParser('autoLinks', function (text, options, globals) {
} 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);

View File

@ -0,0 +1 @@
<p>Just an example <a href="mailto:info@example.com">info@example.com</a> ok?</p>

View File

@ -0,0 +1 @@
Just an example info@example.com ok?

View File

@ -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();
}