mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
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:
parent
90c52b83e7
commit
5190b6a41f
BIN
dist/showdown.js
vendored
BIN
dist/showdown.js
vendored
Binary file not shown.
BIN
dist/showdown.js.map
vendored
BIN
dist/showdown.js.map
vendored
Binary file not shown.
BIN
dist/showdown.min.js
vendored
BIN
dist/showdown.min.js
vendored
Binary file not shown.
BIN
dist/showdown.min.js.map
vendored
BIN
dist/showdown.min.js.map
vendored
Binary file not shown.
|
@ -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);
|
||||
|
|
|
@ -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?
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user