在链接标记上打开新标签页 [英] Open new tab on link markdown

查看:84
本文介绍了在链接标记上打开新标签页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在Stack Overflow上发表我的开发者故事.我添加了一些开源项目,并在说明中添加了一个链接.

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.

我试图确保当您单击简历中的链接时,该链接会在新的tab/window中打开.我搜索并找到了三种方法来做到这一点:

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:

第一种方式:

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

第二种方式:

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

第三种方式:

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

我尝试了三种方式,但没有任何效果.

I tried the three ways but nothing worked.

所以我的问题是,有可能做到这一点吗?

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

如果可能的话,我该怎么办?

If it's possible how can I do that?

推荐答案

在创建Markdown时,XHTML是新的热点,XHTML不允许在元素中使用target属性.因此,Markdown并未获得对target的内置支持(可能还有其他促成该设计决策的因素).

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]是某人试图克服该限制的提案.我不知道任何采用此建议的Markdown实现.如果有的话,那将是非标准且不可移植的.

[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.

属性列表([my link](https://myawesome.link){:target="_blank"})也是非标准的,据我所知,那里的许多Markdown实现中只有三个采用了它.即使这样,它们通常也默认情况下处于关闭状态.您将需要查阅正在使用的实现的文档,以查看它是否受支持,以及是否受支持,如何打开该功能.

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.

当然,原始HTML(<a href="https://myawesome.link" target="_blank">my link</a>)在Markdown中总是可以接受的.但正如您所链接的答案中所解释的那样:

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:

然后,无论如何,它们都将通过HTML白名单过滤器运行整个输出,因为即使是仅Markdown的文档也可以轻松包含XSS攻击.

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

我希望StackExchange(包括StackOverflow)以及许多其他网站都属于这种情况.为了更好地理解人们为什么不喜欢target(以及为什么它在XHTML中无效),请通读以下问题的许多答案:

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?

简而言之,由于XHTML使其无效,因此支持远不如HTML4时代常见.没错,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.

最好的答案是使用原始HTML,如果它不起作用(您正在使用的服务将其删除),则认为这是不可能的.

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.

这篇关于在链接标记上打开新标签页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆