2

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.

The icons are configured inside the file _quarto.yml, like this:

  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.

Rob
  • 14,746
  • 28
  • 47
  • 65
Vinícius Félix
  • 8,448
  • 6
  • 16
  • 32

2 Answers2

3

You can use Lua filter to open external links in a new tab:

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.

The document on how to use Lua filters in Quarto.

TomBen
  • 302
  • 3
  • 6
  • Could you maybe go a bit more into detail of how to make this work? I could not figure out where to put the `.lua` file in my folder and how to get it to run even with the documentation you linked. Thanks a lot in advance! – jpquast Apr 30 '23 at 16:03
  • When using a Pandoc Lua filter, you'll need to make sure that the .lua file is located in the same directory as the input file you're converting with Pandoc. For example, if you have a file called `input.md` that you want to convert using your Lua filter, you should place the Lua file in the same directory as `input.md`. – TomBen May 01 '23 at 00:20
  • Thanks for your reply! I tried adding the `.lua` file just there but I guess I need to somehow let Pandoc or in my case the quarto project know that it should use this file or not? – jpquast May 02 '23 at 20:03
0

Use the target: option within - icon:

navbar:
    left:
      - icon: stack-overflow
        href: https://stackoverflow.com/users/9696037/vin%c3%adciusf%c3%a9lix
        target: _blank

Quarto documentation on navigation items here.

Matt
  • 51
  • 5