Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 3 additions & 3 deletions src/subParsers/makehtml/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<p><a href="https://www.foobar.com">www.foobar.com</a></p>
<p>This is a link <a href="https://www.foobar.com">www.foobar.com</a></p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
www.foobar.com

This is a link <www.foobar.com>
2 changes: 2 additions & 0 deletions test/functional/makehtml/testsuite.features.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
Loading