188

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.

Plaul
  • 7,191
  • 5
  • 19
  • 22

5 Answers5

335

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.

bessbd
  • 570
  • 4
  • 17
Plaul
  • 7,191
  • 5
  • 19
  • 22
  • 70
    +1 For not putting some wrong solution like thousands of other people on StackOverflow. You can't open links in a new tab using markdown (c. 2019). – Benny Schmidt Mar 29 '19 at 03:34
  • 5
    While the answer is correct `users can just do XYZ` is not a solution to this problem. The behavior wanted is clicking on the link to automatically open in a new tab. The behavior with CTRL or CMD + click is adding 1 additional step. Further more unfortunately, other UX decision make CTRL/CMD+click unreliable sometime (Javascript link for instance) which means that the user would need to know what is an actual link and what is not. I wish Markdown just read the HTML at least. – zzarbi Apr 23 '21 at 22:07
18

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.

dpolivaev
  • 494
  • 3
  • 12
2

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.

Ash
  • 168
  • 7
1

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.

Ben Souchet
  • 1,450
  • 6
  • 20
-21

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"}
Zein Sleiman
  • 254
  • 2
  • 11
  • 11
    As of 2019-01-11 neither of these approaches work on GitHub. https://github.com/mojombo/github-flavored-markdown/issues/28 – Brian Wylie Jan 11 '19 at 19:38
  • I might have confused github markdown with github pages. I know on github pages it works. – Zein Sleiman Jan 13 '19 at 02:16
  • 4
    It works for me in Gitpages. The file in repo is https://github.com/mind-maps/software/blob/master/index.md. Render as https://mind-maps.github.io/software/ with target="_blank" – Joy George Kunjikkuru Jun 24 '19 at 22:19
  • 4
    The question clear states "in githubs markdown", and this works in the github page generated from the markdown - so it covers the question pretty well IMO (question could be clarified *a little* as to if it refers to the html generated from the markdown as by github). And it solved my need, so upvoting. – Andrew Mackenzie Apr 11 '20 at 17:36