diff --git a/src/options.js b/src/options.js index fbdc1e0c..0868979c 100644 --- a/src/options.js +++ b/src/options.js @@ -51,6 +51,11 @@ function getDefaultOpts (simple) { describe: 'Turn on/off GFM autolink style', type: 'boolean' }, + httpsAutoLinks: { + defaultValue: false, + describe: 'Use \'https://\' for auto-generated links', + type: 'boolean' + }, literalMidWordUnderscores: { defaultValue: false, describe: 'Parse midword underscores as literal underscores', diff --git a/src/subParsers/makehtml/link.js b/src/subParsers/makehtml/link.js index ff3e5503..b8bb240a 100644 --- a/src/subParsers/makehtml/link.js +++ b/src/subParsers/makehtml/link.js @@ -78,7 +78,7 @@ showdown.subParser('makehtml.link', function (text, options, globals) { let angleBracketsLinksRegex = /<(((?:https?|ftp):\/\/|www\.)[^'">\s]+)>/gi; text = text.replace(angleBracketsLinksRegex, function (wholeMatch, url, urlStart) { let text = url; - url = (urlStart === 'www.') ? 'http://' + url : url; + url = (urlStart === 'www.') ? (options.httpsAutoLinks ? 'https://' : 'http://') + url : url; return writeAnchorTag ('angleBrackets', angleBracketsLinksRegex, wholeMatch, text, null, url); }); @@ -164,8 +164,8 @@ showdown.subParser('makehtml.link', function (text, options, globals) { // we copy the treated url to the text variable let txt = url; - // finally, if it's a www shortcut, we prepend http - url = (urlPrefix === 'www.') ? 'http://' + url : url; + // finally, if it's a www shortcut, we prepend http(s) + url = (urlPrefix === 'www.') ? (options.httpsAutoLinks ? 'https://' : 'http://') + url : url; // url part is done so let's take care of text now // we need to escape the text (because of links such as www.example.com/foo__bar__baz) diff --git a/test/functional/makehtml/cases/features/#806.https-auto-link.html b/test/functional/makehtml/cases/features/#806.https-auto-link.html new file mode 100644 index 00000000..7a14598d --- /dev/null +++ b/test/functional/makehtml/cases/features/#806.https-auto-link.html @@ -0,0 +1,2 @@ +

www.foobar.com

+

This is a link www.foobar.com

\ No newline at end of file diff --git a/test/functional/makehtml/cases/features/#806.https-auto-link.md b/test/functional/makehtml/cases/features/#806.https-auto-link.md new file mode 100644 index 00000000..42306f12 --- /dev/null +++ b/test/functional/makehtml/cases/features/#806.https-auto-link.md @@ -0,0 +1,3 @@ +www.foobar.com + +This is a link \ No newline at end of file diff --git a/test/functional/makehtml/testsuite.features.js b/test/functional/makehtml/testsuite.features.js index 5e8b18a0..567f25a4 100644 --- a/test/functional/makehtml/testsuite.features.js +++ b/test/functional/makehtml/testsuite.features.js @@ -65,6 +65,8 @@ describe('makeHtml() features testsuite', function () { converter = new showdown.Converter({simpleLineBreaks: true}); } else if (testsuite[i].name === '#318.simpleLineBreaks-does-not-work-with-chinese-characters') { converter = new showdown.Converter({simpleLineBreaks: true}); + } else if (testsuite[i].name === '#806.https-auto-link') { + converter = new showdown.Converter({simplifiedAutoLink: true, httpsAutoLinks: true}); } else if (testsuite[i].name === 'simpleLineBreaks-handle-html-pre') { converter = new showdown.Converter({simpleLineBreaks: true}); } else if (testsuite[i].name === 'excludeTrailingPunctuationFromURLs-option') {