When setting the blackfriday option hrefTargetBlank = true, relative links should be kept as is and non-relative links should have target="_blank" added. Looking at the relevant blackfriday source any link begining with "/", "#", etc. should be considered relative, however, in hugo that's not the case for "/".
Working example:
[example link](#{{< relref "example.md" >}})
becomes
<p><a href="#/example.html">example link</a></p>
Broken example:
[example link]({{< relref "example.md" >}})
becomes
<p><a href="/example.html" target="_blank">example link</a></p>
expected result:
<p><a href="/example.html">example link</a></p>
@bep this is actually a bug because blackfriday is not working as expected in hugo.
@bep this is actually a bug because blackfriday is not working as expected in hugo.
It works fine with regular links, not with shortcodes -- that is as designed, and a fix for that is an enhancement in my eyes.
This issue has been automatically marked as stale because it has not been commented on for at least four months.
The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in four months if no further activity occurs. Thank you for all your contributions.
Note/Update: This issue is marked as stale, and I may have said something earlier about "opening a thread on the discussion forum". Please don't.
If this is a bug and you can still reproduce this error on the latest release or the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
I just discovered this issue myself. It is probably Hugo's shortcodes that fools Blackfriday; BF should probably default to relative when not sure, but we can probably fix this on the Hugo side by adjusting the placeholders ... Not sure, will investigate.
Has this been fixed, perhaps? I'm getting the expected behaviour with Hugo 0.54
Not fixed yet. The "_blank" is still added to internal relative links when using Hugo 0.54.0.
Has this been fixed, perhaps? I'm getting the expected behaviour with Hugo 0.54
I just ran into this - have been googling and researching for a solid two hours to see that this is currently a bug.
I also just ran into this with Hugo v0.56.3.
This basically makes hrefTargetBlank and the ref / relref shortcodes incompatible with each other, it seems.
Same here, just ran into this on v0.57.2. It would be great to have this, I like that relref validates relative references, hence I want to use them. But due to this bug (IMO, as though the link is relative, somehow BlackFriday parses it as external, i.e. it's surprising), if I opt in using relref then I have to make all links (both relative and external) to open in the same tab.
Glad I found this GitHub issue, just triggered the same (surprising) behaviour with Hugo v0.59.1. I would have expected that hrefTargetBlank to cause external absolute links to open in a new tab. Since relref is documented to yield a relative permalink, I would assume that hrefTargetBlank does not apply to any links produced by relref.
Most helpful comment
I just discovered this issue myself. It is probably Hugo's shortcodes that fools Blackfriday; BF should probably default to relative when not sure, but we can probably fix this on the Hugo side by adjusting the placeholders ... Not sure, will investigate.