简体   繁体   English

如何使图标默认在新选项卡中打开超链接?

[英]How can I make an icon open a hyperlink in new tab by default?

Currently I have a Quarto Blog with some icons in the navigation menu, each of them have a hyperlink to another site, but they do not open in another tab, instead they open in the same tab as the blog.目前我有一个 Quarto 博客,导航菜单中有一些图标,每个图标都有一个指向另一个站点的超链接,但它们不会在另一个选项卡中打开,而是在与博客相同的选项卡中打开。

The icons are configured inside the file _quarto.yml , like this:图标在文件_quarto.yml中配置,如下所示:

  navbar:
    left:
      - icon: stack-overflow
        href: https://stackoverflow.com/users/9696037/vin%c3%adcius-f%c3%a9lix  

I read the documentation , and did some research, I found methods, such as using target = "_blank" , but I do not know how to configure it inside quarto.我阅读了文档并进行了一些研究,找到了一些方法,例如使用target = "_blank" ,但我不知道如何在 quarto 中配置它。

You can use Lua filter to open external links in a new tab:您可以使用 Lua 过滤器在新选项卡中打开外部链接:

function Link(link)
  if link.target:match '^https?%:' then
    link.attributes.target = '_blank'
    return link
  end
end

The code was shared by @tarleb on Mastodon .该代码由 @tarleb 在Mastodon上共享。

The document on how to use Lua filters in Quarto.关于如何在 Quarto 中使用 Lua 过滤器的文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM