Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to use HTTPS for links without protocol https://github.com/showdownjs/showdown/issues/806 #998

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions src/subParsers/makehtml/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down Expand Up @@ -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)
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 @@ -64,6 +64,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