modify link behaviour in Jekyll

352 Views Asked by At

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!

2

There are 2 best solutions below

3
On BEST ANSWER

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

1
On

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.