Open new tab on link markdown

2019-08-04 18:40发布

问题:

Context

I was currently making my dev' story, here on Stack Overflow. I added some open source projects and I added a link in the description.

Problem

I tried to make that when you click the link in the bio, the link is opened in a new tab/window. I searched and found three ways to do that:

First way:

[my link](https://myawesome.link)[newtab]

Second way:

[my link](https://myawesome.link){:target="_blank"}

Third way:

<a href="https://myawesome.link" target="_blank">my link</a>

I tried the three ways but nothing worked.

Question

So my question is, is it possible to do that?

If it's possible how can I do that?

回答1:

Back when Markdown was created, XHTML was the new hotness and XHTML does not permit use of the target attribute in elements. Therefore, Markdown did not get built-in support for target (there may have been other contributing factors for that design decision).

[my link](https://myawesome.link)[newtab] was someones attempt at a proposal to overcome that limitation. I'm not aware of any Markdown implementation which has adopted this proposal. If there is, it would be non-standard and not portable.

Attribute lists ([my link](https://myawesome.link){:target="_blank"}) are also non-standard and to my knowledge only every adopted by three of the many Markdown implementations out there. Even then, they are usually turned off by default. You will need to consult the documentation for the implementation you are using to see if it is supported, and if so, how to turn the feature on.

Of course, raw HTML (<a href="https://myawesome.link" target="_blank">my link</a>) is always acceptable in Markdown. But as explained in the answer you linked to:

They then run the entire output through an HTML whitelist filter, regardless, since even a Markdown-only document can easily contain XSS attacks.

I expect this is the case with StackExchange (including StackOverflow), along with many other websites. For a better understanding of why people dislike target (and possibly why it was invalid in XHTML) read through a number of answers to the question: Is it alright to use target=“_blank” in HTML5?

In short, it seems that since XHTML made it invalid, support is a lot less common than it was back in the HTML4 days. True, the HTML5 spec brought it back, but it doesn't seem to have the same wide support it once did.

The best answer is to use raw HTML and if that doesn't work (the service you are using strips it out) accept that it is not possible.



标签: markdown