Hyperlinks open in new tab in preview

fixes #174
This commit is contained in:
/Fox --develop 2018-01-04 22:32:13 -08:00 committed by GitHub
parent 6abda7ab68
commit bb2601a566
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1408,6 +1408,31 @@ SimpleMDE.prototype.markdown = function(text) {
};
}
markedOptions.renderer = new marked.Renderer();
markedOptions.renderer.link = function(href, title, text) {
if (this.options.sanitize) {
try {
var prot = decodeURIComponent(unescape(href))
.replace(/[^\w:]/g, '')
.toLowerCase();
} catch (e) {
return '';
}
if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) {
return '';
}
}
if (this.options.baseUrl && !originIndependentUrl.test(href)) {
href = resolveUrl(this.options.baseUrl, href);
}
var out = '<a href="' + href + '"';
if (title) {
out += ' title="' + title + '"';
}
out += ' target="_blank">' + text + '</a>';
return out;
};
// Set options
marked.setOptions(markedOptions);