Open Markdown Links in New Tabs

Posted on

Picture this: you’re reading a blog post. You’re into it. The author, in the middle of the story, shares a link that you might want to look into. You do, because the author has now gained your trust. You check the link and close the tab. Alas, the article is nowhere to be found. You’ve been betrayed.

What happened? The link you’ve clicked on replaced the article you were reading instead of opening a new tab.

This behavior is so preminent in blogs that I’ve developed trust issues.

I know I could just ⌘ + click on these links, but I thought I could trust you.

Don’t worry though. In this blog, I take great care in making sure that links behave as you intend them to.

Most blogs, including this one, use Markdown to write articles. Unfortunately, there’s no standard syntax for opening links in a new tab.

I could have fallback to using HTML with <a target="_blank">. But I’m not a savage, so I had to find something better.

After extensive research, I found a little hack: using base, an HTML tag I’ve never heard of.

I’ve added this tag inside the head of the layout page and it did the job, elegantly:

<head>
    <base target="_blank" />
</head>

Done. Much simpler than I expected.