While playing with render hooks and shortcodes, I was trying to distinguish between several image sources within a render hook for a markdown link.
The link looks like this
[{{< image src="myimage.jpg" >}}](http://myurl)
The image shortcode is quite simple and consists of just two lines:
{{ $src := $.Get "src" }}
<img src="{{ $src }}" />
Last but not least the render hook, taken from the documentation
<a href="{{ .Destination | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}{{ if strings.HasPrefix .Destination "http" }} target="_blank" rel="noopener"{{ end }}>{{ .Text | safeHTML }}</a>
Within the render hook (located in render-link.html) I was trying to check if there’s an image (= the image shortcode) embedded, checking “.Text” or “.PlainText” for containing the string “img” or “image”.
To my surprise, neither “.Text” nor “.PlainText” contained any of these strings.
While investigating further using
<p>Length: {{ len .PlainText }}</p>
<p>Substr 1: {{ substr .PlainText 0 13 }}</p>
<p>Substr 2: {{ substr .PlainText 13 12 }}</p>
within “render-link.html”, I got the result
Length: 25
Substr 1: HAHAHUGOSHORT
Substr 2: CODE-s0-HBHB
Which translates to:
HAHAHUGOSHORTCODE-s0-HBHB
If I don’t split the string and leave “.PlainText” intact, the image is displayed instead of what should be “.PlainText”.
Conclusion: While running a render-hook, shortcodes are translated to an internal format and it’s impossible to check either for the original shortcode tag or the rendered tag.
Question: Is there a way to get either the original shortcode-string or the rendered output from within render-link.html?