Markdownify and target='_blank'

Trying Hugo 0.97.3 ext. I use this target="_blank" shortcode 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.

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.

2 Likes

There was a discussion to deprecate markdownify. I am using $.Page.RenderString in several areas that still require the use of markdownify.

Unfortunately the .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.

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

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>

1 Like

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

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