# Markdownify and target='\_blank'

**URL:** <https://discourse.gohugo.io/t/markdownify-and-target-blank/38315>\
**Category:** support\
**Created:** [April 23, 2022, 5:40am UTC](https://discourse.gohugo.io/t/markdownify-and-target-blank/38315 "2022-04-23T05:40:49Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![baker](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/baker/32/15845_2.png) [@baker](https://discourse.gohugo.io/u/baker)\
**Post date:** [April 23, 2022, 5:40am UTC](https://discourse.gohugo.io/t/markdownify-and-target-blank/38315/1 "2022-04-23T05:40:49Z")

</div>

Trying Hugo 0.97.3 ext. I use this [target="\_blank" shortcode](https://agrimprasad.com/post/hugo-goldmark-markdown/#:~:text=Thus%2C%20if%20you%20want%20to,_blank%22%20attribute%20to%20the%20links.) and with 0.97.3 it fails coz something with markdownify.

This is the original shortcode:  
`<a href="{{ .Destination | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}{{ if strings.HasPrefix .Destination "http" }} target="_blank"{{ end }}>{{ .Text | markdownify }}</a>`

When I remove the ‘`| markdownify`’ from the string it works fine. Is that all? Or is there more to it? Or a better way?

`[google](https://google.com)` renders to:  
`<a href="https://google.com" target="_blank">google</a>` as it should.

---

<div class="post-metadata">

**Author:** ![cshoredaniel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/cshoredaniel/32/19684_2.png) [@cshoredaniel](https://discourse.gohugo.io/u/cshoredaniel)\
**Post date:** [April 23, 2022, 5:53am UTC](https://discourse.gohugo.io/t/markdownify-and-target-blank/38315/2 "2022-04-23T05:53:58Z")

</div>

In 0.97.0, or maybe even 0.96.0, double rendering Markdown is now an error.

You don’t need to translate .Text from markdown to HTML (which is what markdownify does) because in a render-hook (like the render-link hook above) it is already rendered to HTML.

Just leave out the `| markdownify` and you will be fine.

---

<div class="post-metadata">

**Author:** ![tut](https://avatars.discourse-cdn.com/v4/letter/t/e95f7d/32.png) [@tut](https://discourse.gohugo.io/u/tut)\
**Post date:** [April 23, 2022, 7:39am UTC](https://discourse.gohugo.io/t/markdownify-and-target-blank/38315/3 "2022-04-23T07:39:40Z")

</div>

There was [a discussion](https://discourse.gohugo.io/t/deprecate-markdownify/37789) to deprecate `markdownify`. I am using `$.Page.RenderString` in several areas that still require the use of markdownify.

---

<div class="post-metadata">

**Author:** ![baker](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/baker/32/15845_2.png) [@baker](https://discourse.gohugo.io/u/baker)\
**Post date:** [April 23, 2022, 10:40am UTC](https://discourse.gohugo.io/t/markdownify-and-target-blank/38315/4 "2022-04-23T10:40:13Z")

</div>

Unfortunately the [.RenderString](https://gohugo.io/functions/renderstring) page has no real information. There are _Some examples_ mentioned, but don’t show what they render to.

I can’t really figure out how that is used in the above shortcode.

---

<div class="post-metadata">

**Author:** ![tut](https://avatars.discourse-cdn.com/v4/letter/t/e95f7d/32.png) [@tut](https://discourse.gohugo.io/u/tut)\
**Post date:** [April 23, 2022, 12:11pm UTC](https://discourse.gohugo.io/t/markdownify-and-target-blank/38315/5 "2022-04-23T12:11:43Z")

</div>

Where I need to add `| markdownify`, I instead add `| $.Page.RenderString`

---

<div class="post-metadata">

**Author:** ![baker](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/baker/32/15845_2.png) [@baker](https://discourse.gohugo.io/u/baker)\
**Post date:** [April 23, 2022, 2:01pm UTC](https://discourse.gohugo.io/t/markdownify-and-target-blank/38315/6 "2022-04-23T14:01:39Z")

</div>

Whoops, this is not a shortcode! My bad. It’s in `layouts/_default/_markup/render-link.html`

@tut  
When I change it it crashes Hugo.

`<a href="{{ .Destination | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}{{ if strings.HasPrefix .Destination "http" }} target="_blank"{{ end }}>{{ .Text | $.Page.RenderString }}</a>`

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [April 23, 2022, 2:06pm UTC](https://discourse.gohugo.io/t/markdownify-and-target-blank/38315/7 "2022-04-23T14:06:01Z")

</div>

Please read the response from @cshoredaniel again.  
Read it carefully.

His response was marked as the accepted solution because it it correct.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [April 23, 2022, 2:06pm UTC](https://discourse.gohugo.io/t/markdownify-and-target-blank/38315/8 "2022-04-23T14:06:09Z")

</div>


