# How to target="\_blank" in .md?

**URL:** <https://discourse.gohugo.io/t/how-to-target--blank-in-md/524>\
**Category:** support\
**Created:** [December 30, 2014, 9:37pm UTC](https://discourse.gohugo.io/t/how-to-target--blank-in-md/524 "2014-12-30T21:37:34Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheLoneCuber](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/thelonecuber/32/71_2.png) [@TheLoneCuber](https://discourse.gohugo.io/u/TheLoneCuber)\
**Post date:** [December 30, 2014, 9:37pm UTC](https://discourse.gohugo.io/t/how-to-target--blank-in-md/524/1 "2014-12-30T21:37:34Z")

</div>

Is it possible to target="\_blank" in Hugo without resorting to inline HTML?

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [December 30, 2014, 9:42pm UTC](https://discourse.gohugo.io/t/how-to-target--blank-in-md/524/2 "2014-12-30T21:42:33Z")

</div>

Dont’t think so.

But this is a question better asked to [https://github.com/russross/blackfriday](https://github.com/russross/blackfriday) - the Markdown engine in Hugo.

---

<div class="post-metadata">

**Author:** ![anthonyfok](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/anthonyfok/32/106_2.png) [@anthonyfok](https://discourse.gohugo.io/u/anthonyfok)\
**Post date:** [December 31, 2014, 6:59am UTC](https://discourse.gohugo.io/t/how-to-target--blank-in-md/524/3 "2014-12-31T06:59:16Z")

</div>

Hi @TheLoneCuber,

There is also an interesting answer on StackOverflow to automatically add `target="_blank"` to external links with JavaScript:

> <https://stackoverflow.com/questions/4425198/can-i-create-links-with-target-blank-in-markdown>

---

<div class="post-metadata">

**Author:** ![juliendubreuil](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/juliendubreuil/32/144_2.png) [@juliendubreuil](https://discourse.gohugo.io/u/juliendubreuil)\
**Post date:** [December 31, 2014, 10:40am UTC](https://discourse.gohugo.io/t/how-to-target--blank-in-md/524/4 "2014-12-31T10:40:50Z")

</div>

The only way I found is to use HTML (I’m not happy with that but this is the only solution). Or you can do what @anthonyfok suggests to you, using javascript even if it looks worst to me (my 2 cents)

---

<div class="post-metadata">

**Author:** ![spf13](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/spf13/32/37_2.png) [@spf13](https://discourse.gohugo.io/u/spf13)\
**Post date:** [December 31, 2014, 3:13pm UTC](https://discourse.gohugo.io/t/how-to-target--blank-in-md/524/5 "2014-12-31T15:13:58Z")

</div>

You could also use a shortcode, but I think this is probably overkill.

The right answer here is to use HTML.

Markdown is intentionally simplistic. It gives you very little control over how things are rendered. However Markdown + Hugo gives you two great things to allow you the control you want. HTML is valid markdown, so you can use that if you want more control. Additionally Hugo provides shortcodes to provide even more powerful functionality inside of posts.

---

<div class="post-metadata">

**Author:** ![juliendubreuil](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/juliendubreuil/32/144_2.png) [@juliendubreuil](https://discourse.gohugo.io/u/juliendubreuil)\
**Post date:** [December 31, 2014, 3:41pm UTC](https://discourse.gohugo.io/t/how-to-target--blank-in-md/524/6 "2014-12-31T15:41:18Z")

</div>

> [@spf13](#):
>
> You could also use a shortcode, but I think this is probably overkill.

I tried this solution by the past but it wasn’t a good thing to do, I figured out when I wanted to move my contents (in markdown) to another static page generator. I had to redevelop the url plugin to interpret what was that code in my content. Breaking the simplicity of creating an url break the possibility to switch easily of solution.

---

<div class="post-metadata">

**Author:** ![anthonyfok](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/anthonyfok/32/106_2.png) [@anthonyfok](https://discourse.gohugo.io/u/anthonyfok)\
**Post date:** [December 31, 2014, 7:02pm UTC](https://discourse.gohugo.io/t/how-to-target--blank-in-md/524/7 "2014-12-31T19:02:11Z")

</div>

Probably off-topic here, but something to look forward to when Hugo supports `.adoc`, i.e. AsciiDoc (either via the @VonC’s [asciidocgo](https://github.com/VonC/asciidocgo) Go library or external Asciidoctor), which has a shorthand for `target="_blank"`:

[http://asciidoctor.org/docs/asciidoc-writers-guide/#target-window-and-role-attributes-for-links](http://asciidoctor.org/docs/asciidoc-writers-guide/#target-window-and-role-attributes-for-links)

---

<div class="post-metadata">

**Author:** ![TheLoneCuber](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/thelonecuber/32/71_2.png) [@TheLoneCuber](https://discourse.gohugo.io/u/TheLoneCuber)\
**Post date:** [January 2, 2015, 5:26am UTC](https://discourse.gohugo.io/t/how-to-target--blank-in-md/524/8 "2015-01-02T05:26:01Z")

</div>

I clearly need to look into shortcodes because I haven’t [yet]. They sound handy.

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [January 26, 2015, 6:51pm UTC](https://discourse.gohugo.io/t/how-to-target--blank-in-md/524/9 "2015-01-26T18:51:59Z")

</div>

I made a quick custom Blackfriday renderer to test “custom links”:

> <https://github.com/gohugoio/hugo/pull/843>

Works fine - but I’m not sure if it’s a good idea in real life and how it should be set up (only for external links?) …

---

<div class="post-metadata">

**Author:** ![trombonehero](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/trombonehero/32/200_2.png) [@trombonehero](https://discourse.gohugo.io/u/trombonehero)\
**Post date:** [January 27, 2015, 2:30am UTC](https://discourse.gohugo.io/t/how-to-target--blank-in-md/524/10 "2015-01-27T02:30:48Z")

</div>

Hi all,

It would be fantastic if the custom blackfriday rendering could automatically be hooked up a shortcode provided by a theme or by the site itself (see [GitHub issue 836](https://github.com/spf13/hugo/issues/836)). That is, if there is a template in either of:

- `/layouts/shortcodes/link.html`
- `/themes/THEME/layouts/shortcodes/link.html`

then that template could be called with parameters `url` and `text`.

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [January 27, 2015, 8:25am UTC](https://discourse.gohugo.io/t/how-to-target--blank-in-md/524/11 "2015-01-27T08:25:29Z")

</div>

@trombonehero if that’s what you need, that is possible today: Just create a shortcode.

A custom renderer could be useful for stuff that is not natural to solve with a sc.

One could imagine Hugo adding a config parameter saying:

- addBlankTargetToExtternalLinksInMarkdown

And do a check for urls not starting with single “/”.

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [June 21, 2015, 5:36pm UTC](https://discourse.gohugo.io/t/how-to-target--blank-in-md/524/12 "2015-06-21T17:36:49Z")

</div>

See

> <https://github.com/gohugoio/hugo/issues/1220>

This would be a global or per page setting, but better than nothing.

Pull requests welcome. Should be pretty straight forward, just look at the previous similar additions. Just ask.

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [June 28, 2015, 1:35pm UTC](https://discourse.gohugo.io/t/how-to-target--blank-in-md/524/13 "2015-06-28T13:35:11Z")

</div>

The above issue is added to the latest source.

---

<div class="post-metadata">

**Author:** ![SvenDowideit](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/svendowideit/32/670_2.png) [@SvenDowideit](https://discourse.gohugo.io/u/SvenDowideit)\
**Post date:** [December 11, 2015, 5:30am UTC](https://discourse.gohugo.io/t/how-to-target--blank-in-md/524/14 "2015-12-11T05:30:12Z")

</div>

mmm, and of course, we need a non-global way to do this 😕 - using the source level linking - oh joys - which is only triggered for markdown style links.

---

<div class="post-metadata">

**Author:** ![spf13](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/spf13/32/37_2.png) [@spf13](https://discourse.gohugo.io/u/spf13)\
**Post date:** [December 11, 2015, 5:31am UTC](https://discourse.gohugo.io/t/how-to-target--blank-in-md/524/15 "2015-12-11T05:31:40Z")

</div>

only way to do it one off is inline HTML or a Shortcode. That is the defined way to do it in Markdown.

---

<div class="post-metadata">

**Author:** ![SvenDowideit](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/svendowideit/32/670_2.png) [@SvenDowideit](https://discourse.gohugo.io/u/SvenDowideit)\
**Post date:** [December 11, 2015, 5:40am UTC](https://discourse.gohugo.io/t/how-to-target--blank-in-md/524/16 "2015-12-11T05:40:36Z")

</div>

I’m going to port the GitHub linking PR to use mmark (as well as blackfriday) - as [https://github.com/fletcher/MultiMarkdown/wiki/MultiMarkdown-Syntax-Guide#anchor-and-image-attributes](https://github.com/fletcher/MultiMarkdown/wiki/MultiMarkdown-Syntax-Guide#anchor-and-image-attributes) gives me hope.

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [December 11, 2015, 9:14am UTC](https://discourse.gohugo.io/t/how-to-target--blank-in-md/524/17 "2015-12-11T09:14:33Z")

</div>

> [@SvenDowideit](#):
>
> mmm, and of course, we need a non-global way to do this 😕 - using the source level linking - oh joys - which is only triggered for markdown style links.

A slightly non-global way to do it is to set this Blackfriday option on a per-page basis … But I suspect this isn’t non-global enough.

---

<div class="post-metadata">

**Author:** ![rdwatters](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rdwatters/32/2848_2.png) [@rdwatters](https://discourse.gohugo.io/u/rdwatters)\
**Post date:** [December 11, 2015, 11:26pm UTC](https://discourse.gohugo.io/t/how-to-target--blank-in-md/524/18 "2015-12-11T23:26:42Z")

</div>

@bep and @SvenDowideit, am I missing something? I’ve set the following in my `config.toml` and it works like a charm:

```auto
[blackfriday]
   plainIDAnchors = true
   hrefTargetBlank = true

```

I have some handy javascript to that controls for things like `mailto` and also works for href’s ending in .pdf, excel, etc. Let me know if I can help. Cheers.

Oh yeah, and some JS for extra formatting flexibility with blockquotes. I hate using inline HTML in markdown if I can help it, since I think of markdown as an abstraction of all markup languages and not _just_ HTML.

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [December 11, 2015, 11:32pm UTC](https://discourse.gohugo.io/t/how-to-target--blank-in-md/524/19 "2015-12-11T23:32:29Z")

</div>

> [@rdwatters](#):
>
> @bep and @SvenDowideit, am I missing something?

He wants to set it on a per-link basis. Currently you can set the target=\_blank on site or per page.

---

<div class="post-metadata">

**Author:** ![rdwatters](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rdwatters/32/2848_2.png) [@rdwatters](https://discourse.gohugo.io/u/rdwatters)\
**Post date:** [December 12, 2015, 9:44pm UTC](https://discourse.gohugo.io/t/how-to-target--blank-in-md/524/20 "2015-12-12T21:44:48Z")

</div>

Ah, terribly sorry. Figured I was missing something. I’m curious about this use case @SvenDowideit. Why would you need such granular control on a per-anchor basis? My assumption would just be for anchors to external sites and non-HTML documents (eg, .docx, .pdf, etc).

[Next page](https://discourse.gohugo.io/t/how-to-target--blank-in-md/524.md?page=2)
