1

I have an itchy issue I definitely need solve.

Every time I insert a link in my Jekyll website, independently if I write it in a Markdown file or an HTML file, I write the following:

<a href="http://example.com" rel="noopener noreferrer" target="_blank">example</a>

Obviously, it's way longer, more boring and more stressful than typing

[example](example.com)

Is there a way I can add by default the rel and target attributes (maybe in the _config.yml file) for every link so that I can easily insert a simple <a> tag and then it's parsed with all the extra stuff?

I know I could insert attributes also in Markdown, like this, but it's still quite a lot of typing...

Thanks a lot in advance, this would definitely change my game!

Tommi
  • 13
  • 3
  • You may want to consider looking at this post for inspiration https://stackoverflow.com/questions/4425198/can-i-create-links-with-target-blank-in-markdown – Kin May 27 '20 at 18:05

2 Answers2

0

My past Jekyll project was able to leverage a fork of Jekyll Target Blank that added rel and target attributes to <a> tags.

Kin
  • 1,435
  • 10
  • 16
  • This is **great**, thanks! Does it work with GitHub Pages || Netlify? Thanks again you saved me hours of useless typing. I love you. – Tommi May 27 '20 at 15:08
  • @Tommi We did not use GitHub Pages or Netlify, so I don't know if `jekyll-target-blank` works with those hosting platforms. We self-hosted our Jekyll project. – Kin May 27 '20 at 18:03
  • Got it. Thank you anyways. Have a nice day – Tommi May 28 '20 at 09:39
0

Kramdown supports it this way (as you mentioned):

[example](example.com){:target="_blank"}{:rel="noopener noreferrer"}

If you want to do it for all links across your site, you'd need to write a custom plugin, which wouldn't work on GitHub Pages, or use Javascript.

Brad West
  • 943
  • 7
  • 19
  • If I have to write all that stuff, it doesn’t change much from HTML, I’d use that. Thanks anyway. – Tommi May 29 '20 at 21:45