You could write your own Pandoc Lua Filter which adds target="_blank"
to all links:
- Write a Pandoc Lua Filter, name it for example
links.lua
function Link(element)
if
-- ignore in-book references
string.sub(element.target, 1, 1) ~= "#"
then
element.attributes.target = "_blank"
end
return element
end
- Then update your
_output.yml
bookdown::gitbook:
pandoc_args:
- --lua-filter=links.lua
An alternative solution would be to inject <base target="_blank">
in the HTML head
section using the includes
option:
- Create a new HTML file, name it for example
links.html
<base target="_blank">
- Then update your
_output.yml
bookdown::gitbook:
includes:
in_header: links.html
Also posted here: https://stackoverflow.com/a/71230269/42659