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 17 additions and 11 deletions

9
dist/showdown.js vendored
View File

@ -1323,8 +1323,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);
@ -1352,8 +1352,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);
@ -1361,7 +1362,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);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

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