open link in new tab with github markdown using target="_blank"

GithubHyperlinkMarkup

Github Problem Overview


Is there a way to let a Link, written in githubs markdown, open in a new tab? All posts I have found related to this suggests to use HTML and target="_blank", which is fine with me, but that doesn't work. For example this link:

<a href="http://stackoverflow.com" target="_blank">Go</a>

Does not open in a new tab. I'm no interested in replies for all kind of different markdown syntaxes, but only in a solution that will work when I write my markdown on github.

Github Solutions


Solution 1 - Github

Well it seems that the simple answer is "It's not possible". Github does not include the target attribute even if you use plain HTML, so it's not a in the final HTML Anchor tag. Annoying, but OK, users can just do a CTRL+click (on Windows and Linux) or CMD+click (on MacOS) on the link, the get the same behavior.

Solution 2 - Github

There is a solution specific to websites using GitHub pages: adding line

markdown: kramdown

to file _config.yml, you can use [go](http://stackoverflow.com){:target="_blank" rel="noopener"} because then GitHub pages engine uses another markdown called kramdown for generating html. However, it does not work on previews and in markdown rendered by GitHub directly in the project repository.

Solution 3 - Github

From what I have read and researched, it is not possible. I wanted to do something similar but soon realized that it is not a feature in git md, unfortunately.

Solution 4 - Github

It's possible for Github Pages users (Jekyll), the proper way (March 2022) is to add to your _config.yml file these lines:

kramdown:
  input: Kramdown

This is specified in the documentation:

> You can also change the processor used by Kramdown (as specified for the input key in the Kramdown RDoc). For example, to use the non-GFM Kramdown processor in Jekyll, add the following to your configuration.

Use the Kramdown processor instead of GFM will allow you to add {:target="_blank" rel="noopener"} to markdown links to tell the browser to open link in new tab.

Example
[Stackoverflow The Key](https://stackoverflow.blog/2021/03/31/the-key-copy-paste/){:target="_blank" rel="noopener"}

/!\ Disclaimer

Changing the markdown processor from GFM (default value) to kramdown can create issues in the HTML result, since all the specific features of GitHub Flavored Markdown (GFM) won't work anymore.

Solution 5 - Github

The answer should be what @Idavid posted in a comment.

[go](http://stackoverflow.com){:target="_blank"}.

You should also add rel="noopener"

[go](http://stackoverflow.com){:target="_blank" rel="noopener"}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPlaulView Question on Stackoverflow
Solution 1 - GithubPlaulView Answer on Stackoverflow
Solution 2 - GithubdpolivaevView Answer on Stackoverflow
Solution 3 - GithubAshView Answer on Stackoverflow
Solution 4 - GithubBen SouchetView Answer on Stackoverflow
Solution 5 - GithubZein SleimanView Answer on Stackoverflow