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

Add option to add target="_blank" when parsing links #222

Closed
SekibOmazic opened this issue Dec 7, 2015 · 3 comments
Closed

Add option to add target="_blank" when parsing links #222

SekibOmazic opened this issue Dec 7, 2015 · 3 comments
Assignees

Comments

@SekibOmazic
Copy link

Would be nice to have an option that adds target="_blank" on parsed links.

@tivie
Copy link
Member

tivie commented Jan 1, 2016

Hey @SekibOmazic.

This "option" makes more sense as an extension rather than something embeded on core.

@rabeesh
Copy link

rabeesh commented May 11, 2016

It will be nice to support feature to convert

[adjustable](http://google.com "Giiidd"){:target="_blank"}

@tivie
Copy link
Member

tivie commented Jul 21, 2016

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 html

fiddle

some text with a link <a href="http://www.google.com" target="blank">google</a>

Create an extension

fiddle

showdown.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, '&quot;');
        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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants