177

I'm trying to edit a website which uses a modx cms, and it's using Markdown. Now I would like to open a new link into another window.

Is it possible?

The Link [Registration](http://www.registration.com)
halfer
  • 19,824
  • 17
  • 99
  • 186
tintincutes
  • 5,618
  • 25
  • 67
  • 86

5 Answers5

231

There is no such feature in markdown, however you can always use HTML inside markdown:

<a href="http://example.com/" target="_blank">example</a>
Vladimir Keleshev
  • 13,753
  • 17
  • 64
  • 93
  • 8
    Thank you for the reply. I also noticed that there is no feature in Markdown. I find it quite not friendly user – tintincutes May 02 '11 at 09:27
  • 5
    Markdown provides shorthand for the most common features of HTML. One of its best features is that you can always fallback to the full syntax for HTML. This includes doing things that aren't included in markdown. Personally, I like that markdown is concise and includes very little fluff. It makes it easier to learn the whole set of shorthand. This is particularly important if you expect someone else to read your code later. – justis Feb 20 '12 at 02:33
  • Great response, no need to be stuck by some of the limitations of Markdown, and I should note, this combination (MD/HTML) works great on GitHub. – niczak Sep 28 '14 at 12:48
  • 11
    This is pretty old now, but it should absolutely be mentioned that you can ***NOT*** always fall back to html - I suspect that MOST places that support markdown don't support html. Proof – Maverick May 22 '15 at 07:17
  • 29
    Just tried this on Github and it does not work as expected. Looks like they strip out the `target="_blank"` upon rendering for some reason. Thanks Github! – Brian FitzGerald Dec 29 '16 at 17:32
  • This is just a rant, but I'm personally quite frustrated by MarkDown, bbcode, JIRA formatting, and similar markup. They're confusingly different standards for doing pretty much the same thing, are all missing basic HTML features (this question is an example), and as @Maverick points out, even if you get used to just one, things don't always work. Browsers eventually standardised their interpretation of HTML, but this doesn't seem to be happening with this kind of markup. I suppose over 20 years of coding will get anyone used to anything, but plain ol' HTML is much easier, IMHO. – Michael Scheper Mar 02 '17 at 18:18
  • @MichaelScheper It's also a security risk and much lengthier to type. There _are_ practical reasons why Markdown is so popular. – Qix - MONICA WAS MISTREATED Jun 29 '17 at 07:18
  • 2
    @Qix: There are reasons WIndows is popular, too, but I don't find those very compelling either. And considering the answer to so many 'how do I do this in MarkDown' questions is 'use HTML, since MarkDown supports it', the security risk argument doesn't make sense. Numerous social media and forum sites support HTML and they don't seem particularly prone to security issues. I'm happy to try to reach agreement with you, but this isn't the right place. Feel free to invite me to a more appropriate forum. – Michael Scheper Jul 06 '17 at 23:08
  • I did get this to work with github (kindof) I am rendering git pages as a window within my web page. using this allowed the links to open in a new tab were before they tried to open in the embedded window where they would fail to load at all. when the git page was open in its own tab the links would still open in the same tab. very strange behavior. – Jeff Sep 05 '17 at 17:02
  • The concept is correct, but it may not work in any given environment, due to how security is defined. For one...TFS wiki pages. – klewis Nov 15 '18 at 21:05
  • It's not even working in Google Chrome as: Should Open in New Tab – Rahim Aug 29 '22 at 10:31
104

As suggested by this answer:

[link](url){:target="_blank"}

Works for jekyll or more specifically kramdown, which is a superset of markdown, as part of Jekyll's (default) configuration. But not for plain markdown. ^_^

Frank N
  • 9,625
  • 4
  • 80
  • 110
shellbye
  • 4,620
  • 4
  • 32
  • 44
4

Using sed

If one would like to do this systematically for all external links, CSS is no option. However, one could run the following sed command once the (X)HTML has been created from Markdown:

sed -i 's|href="http|target="_blank" href="http|g' index.html

This can be further automated in a single workflow when a Makefile with build instructions is employed.

PS: This answer was written at a time when extension link_attributes was not yet available in Pandoc.

Community
  • 1
  • 1
Serge Stroobandt
  • 28,495
  • 9
  • 107
  • 102
1

It is very dependent of the engine that you use for generating html files. If you are using Hugo for generating htmls you have to write down like this:

<a href="https://example.com" target="_blank" rel="noopener"><span>Example Text</span> </a>.
Henaras
  • 21
  • 4
-3

You can edit the generated markup and add

target = "_blank"
Osinachi
  • 656
  • 8
  • 14