We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

Adam Ormsby • 6 years ago

Hey, this is super useful! One thing you might update --
{{ .Text | markdownify }}
This would make sure that all characters display properly instead of accidentally converting to HTML name codes (happened with my quotes!). Thanks for the code! :)

Roshan Jonah • 4 years ago

This works within a markdown file but if I have the markdown within a shortcode like this...
<div class="inverse__content">
{{ .Inner | markdownify | safeHTML }}
</div>

Then the links within that DIV are not getting the same target _blank added :(

Is there any way around this, Agrim? Thank you :)

C/Rusty • 4 years ago

Try
<div class="inverse__content">
{{ .Inner | $.Page.RenderString | safeHTML }}
</div>

See Markdownify function does not call render-link hook #6650

megacron • 6 years ago

This was driving me nuts! Wish Hugo would do a better job of informing us of such things. :/
Thanks a bunch Agrim.

Darko • 6 years ago

Thanks! Works like a charm

Agrim Prasad • 6 years ago

Thanks for your comment Darko. Glad that it worked well for you.

Paul • 3 years ago

Very nice solution, but the one thing this does and I can't seem to fix it, is add a space after the link if there is a character directly behind it.

So with:
[Link](https://example.com), hello.
You will get:
Link , hello.

Whereas with:
<a target="_blank" href="https://example.com">Link</a>, hello.

You get:
Link, hello.

Not sure what the cause is, because I don't see any spaces outside the link code in the render-link itself..

Mike Akister • 4 years ago

Not sure if anyone lese is having this issue but I can no longer use relative links for internal blog links. Other than that it works great!

Shariq Jamil • 4 years ago

Thanks a million, works great!

Ryan Gillett • 5 years ago

I've solved this by adding <base target="_blank"> to the partial head

Kyle • 5 years ago

thank you for explaining this, worked like a charm!

Piotr • 5 years ago

Awesome. Although for a content with special characters htmlUnescape or safeHTML has to be used: {{ .Text | safeHTML }}.

Jess Rascal • 5 years ago

Good tip and it worked in local dev, but I was having issues with getting this working in Production (hosted on Netlify).

It turns out it was because this method is only compatible with Hugo v0.62.0+

To fix this, I needed to set the Hugo version that Netlify uses for my site by adding the following to my Netlify.toml file.


[context.production.environment]
HUGO_VERSION = "0.65.3"

You can set the version to whichever you want (I'm currently using v0.65.3), just make sure it's at least 0.62.0.

Note: If you don't already have a Netlify.toml file, then just create it in the root of your site.

zacharybk • 5 years ago

Thank you for your help! I would love to see the TLDR at the top of the post ;)

sosure • 6 years ago

Just save my day.
Thanks

Boon • 6 years ago

This work for me. Hugo 0.64.0 Thanks for sharing.