|
@@ -1,4 +1,4 @@
|
|
|
-;/*! showdown 30-11-2016 */
|
|
|
+;/*! showdown 01-12-2016 */
|
|
|
(function(){
|
|
|
/**
|
|
|
* Created by Tivie on 13-07-2015.
|
|
@@ -38,6 +38,11 @@ function getDefaultOpts(simple) {
|
|
|
describe: 'Turn on/off GFM autolink style',
|
|
|
type: 'boolean'
|
|
|
},
|
|
|
+ excludeTrailingPunctuationFromURLs: {
|
|
|
+ defaultValue: false,
|
|
|
+ describe: 'Excludes trailing punctuation from links generated with autoLinking',
|
|
|
+ type: 'boolean'
|
|
|
+ },
|
|
|
literalMidWordUnderscores: {
|
|
|
defaultValue: false,
|
|
|
describe: 'Parse midword underscores as literal underscores',
|
|
@@ -115,6 +120,7 @@ var showdown = {},
|
|
|
omitExtraWLInCodeBlocks: true,
|
|
|
prefixHeaderId: 'user-content-',
|
|
|
simplifiedAutoLink: true,
|
|
|
+ excludeTrailingPunctuationFromURLs: true,
|
|
|
literalMidWordUnderscores: true,
|
|
|
strikethrough: true,
|
|
|
tables: true,
|
|
@@ -1185,9 +1191,10 @@ showdown.subParser('autoLinks', function (text, options, globals) {
|
|
|
|
|
|
text = globals.converter._dispatch('autoLinks.before', text, options, globals);
|
|
|
|
|
|
- var simpleURLRegex = /\b(((https?|ftp|dict):\/\/|www\.)[^'">\s]+\.[^'">\s]+)(?=\s|$)(?!["<>])/gi,
|
|
|
+ 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,
|
|
|
+ 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;
|
|
|
|
|
|
text = text.replace(delimUrlRegex, replaceLink);
|
|
@@ -1196,20 +1203,28 @@ showdown.subParser('autoLinks', function (text, options, globals) {
|
|
|
// Email addresses: <address@domain.foo>
|
|
|
|
|
|
if (options.simplifiedAutoLink) {
|
|
|
- text = text.replace(simpleURLRegex, replaceLink);
|
|
|
+ if (options.excludeTrailingPunctuationFromURLs) {
|
|
|
+ text = text.replace(simpleURLRegex2, replaceLink);
|
|
|
+ } else {
|
|
|
+ text = text.replace(simpleURLRegex, replaceLink);
|
|
|
+ }
|
|
|
text = text.replace(simpleMailRegex, replaceMail);
|
|
|
}
|
|
|
|
|
|
- function replaceLink(wm, link) {
|
|
|
- var lnkTxt = link;
|
|
|
+ function replaceLink(wm, link, m2, m3, trailingPunctuation) {
|
|
|
+ var lnkTxt = link,
|
|
|
+ append = '';
|
|
|
if (/^www\./i.test(link)) {
|
|
|
link = link.replace(/^www\./i, 'http://www.');
|
|
|
}
|
|
|
- return '<a href="' + link + '">' + lnkTxt + '</a>';
|
|
|
+ if (options.excludeTrailingPunctuationFromURLs && trailingPunctuation) {
|
|
|
+ append = trailingPunctuation;
|
|
|
+ }
|
|
|
+ return '<a href="' + link + '">' + lnkTxt + '</a>' + append;
|
|
|
}
|
|
|
|
|
|
- function replaceMail(wholeMatch, m1) {
|
|
|
- var unescapedStr = showdown.subParser('unescapeSpecialChars')(m1);
|
|
|
+ function replaceMail(wholeMatch, mail) {
|
|
|
+ var unescapedStr = showdown.subParser('unescapeSpecialChars')(mail);
|
|
|
return showdown.subParser('encodeEmailAddress')(unescapedStr);
|
|
|
}
|
|
|
|