-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add option to add target="_blank"
when parsing links
#222
Comments
Hey @SekibOmazic. This "option" makes more sense as an extension rather than something embeded on core. |
It will be nice to support feature to convert
|
Adding extra syntax to the link element is not a good idea as it diverts from the markdown spec and breaks compatibility. However, there are 2 easy ways to add this to links: Using embeded htmlsome text with a link <a href="http://www.google.com" target="blank">google</a> Create an extensionshowdown.extension('targetlink', function() {
return [{
type: 'lang',
regex: /\[((?:\[[^\]]*]|[^\[\]])*)]\([ \t]*<?(.*?(?:\(.*?\).*?)?)>?[ \t]*((['"])(.*?)\4[ \t]*)?\)\{\:target=(["'])(.*)\6}/g,
replace: function(wholematch, linkText, url, a, b, title, c, target) {
var result = '<a href="' + url + '"';
if (typeof title != 'undefined' && title !== '' && title !== null) {
title = title.replace(/"/g, '"');
title = showdown.helper.escapeCharacters(title, '*_', false);
result += ' title="' + title + '"';
}
if (typeof target != 'undefined' && target !== '' && target !== null) {
result += ' target="' + target + '"';
}
result += '>' + linkText + '</a>';
return result;
}
}];
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would be nice to have an option that adds
target="_blank"
on parsed links.The text was updated successfully, but these errors were encountered: