Not converting foo?a/b to foo?a%2fb

I’m making a short code for linking to java doc.
The with-frame java docs is a bit crazy, as it wants href to be ....?../.../ , and replacing / by %2f doesn’t work. ( e.g. )

My shortcode is simply
<a href="{{.Get 0}}"> {{.Inner}}</a>
And usage is
{{% ref "java/lang/System.html" %}} System {{% /ref %}}
This results in
<a href=""> System</a>

I tried various functions in shortcode, but nothing generates the ‘/’ .

Now, the question is, how to make hugo emit ‘/’ instead of ‘%2f’, after it has seen the ‘?’ of href ?
I’ld prefer to handle it in shortcode, rather than md,


Try the piping your shortcode output to the safeHTML function.

Unfortunately that still generates %2f for ‘/’

Go template security contexts can be tricky. Try generating the entire href attribute.

<a {{ printf "href=\"\"" (.Get 0) | safeHTMLAttr }}>

PS: Edited since I posted the wrong version of my comment. Too may tabs open!

1 Like