diff --git a/src/options.js b/src/options.js index 19deb667..30e346db 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/links.js b/src/subParsers/makehtml/links.js index cac80da7..4c7f5305 100644 --- a/src/subParsers/makehtml/links.js +++ b/src/subParsers/makehtml/links.js @@ -302,7 +302,7 @@ var urlRgx = /<(((?:https?|ftp):\/\/|www\.)[^'">\s]+)>/gi; text = text.replace(urlRgx, function (wholeMatch, url, urlStart) { var text = url; - url = (urlStart === 'www.') ? 'http://' + url : url; + url = (urlStart === 'www.') ? (options.httpsAutoLinks ? 'https://' : 'http://') + url : url; var evt = createEvent(urlRgx, evtRootName + '.captureStart', wholeMatch, text, null, url, null, options, globals); return writeAnchorTag(evt, options, globals); }); @@ -392,7 +392,7 @@ // we copy the treated url to the text variable var text = url; // finally, if it's a www shortcut, we prepend http - url = (urlPrefix === 'www.') ? 'http://' + url : url; + 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 @@ +
+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