-
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
Way to add target in links #247
Comments
+1 for this feature. |
is there any work around for now? |
Adding extra syntax to the link element is not a good idea as it diverts from the markdown spec and breks 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 extensionSyntax
Test onlineCodeshowdown.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;
}
}];
}); |
In case anyone is using the extension code above there is a bug - if two links are placed next to each other... the correct RE is this:
Fixed Extension Code
|
I took a look in the web and I found something about.
Okay, we can add the pure HTML inside the markdown, but would me amazing, and better a way to do it easily like:
The text was updated successfully, but these errors were encountered: