When I remove all linebreaks within the html-code of the img-template it renders correctly, but makes the code hard to maintain since the actual shortcode we use is much bigger than the simplified example. I already tried many things like adding markdownify in multiple places and also adding {{$_hugo_config:={ "version": 1 } }} in the shortcode templates. The weird thing is that all shortcodes render, only that the generated html code of the last shortcode is interpreted as text.
Sadly we didn’t notice the problem for some time as it is only used on a sub-page. It might have worked with Hugo 0.98, for certain it worked with the very old v0.68.3
{{- $src := .Get "src" }}
{{- $height := or (.Get "height") 200 }}
{{- $width := or (.Get "width") 300 }}
{{- $alt := or (.Get "alt") "" }}
{{- $noZoom := or (.Get "noZoom") true -}}
<img
height="{{ $height }}"
width="{{ $width }}"
alt="{{ $alt }}"
src="{{ $src }}"
{{- if (not $noZoom) }}
onClick="zoomImage({{ $src }})"
{{- else }}
class="no-zoom"
{{- end -}}
>
{{- /* keep this comment... it chomps the trailing new line */ -}}
Try it:
git clone --single-branch -b hugo-forum-topic-47869 https://github.com/jmooring/hugo-testing hugo-forum-topic-47869
cd hugo-forum-topic-47869
hugo server
Comments
The change in behavior from whatever version you were running before is due to changes made in v0.55.0 and v0.60.0.
Thanks, your solution definitely works, though I already have unsafe = true set in the config. I exchanged my code step by step with yours and found that my img-shortcode is the problem, since it works fine if I replace it with yours. (cute cat btw!)
Here is the full version of my img-shortcode that only works if I remove all line-breaks:
Thank you so much! I removed all indentation to test it and it still doesn’t look correct. The version that works is this, but it makes it quire hard to maintain the code:
git clone --single-branch -b hugo-forum-topic-47869 https://github.com/jmooring/hugo-testing hugo-forum-topic-47869
cd hugo-forum-topic-47869
hugo server
Mixing markdown with raw HTML is complicated; both indentation and blank lines are important.
If you look at the diff above, all we’re doing for each conditional image block is:
Removing one blank line
Making sure that > is not on its own line (that’s markdown syntax for a blockquote)
For shortcodes and render hooks, I usually start every line with {{- so that I don’t have to think about it (much), and I make sure to end the template with either -}} or {{- /**/ -}} to chomp the trailing new line. This is important for inline elements such as images and links to prevent unwanted spacing between adjacent elements.
Thank you so much for your effort and the thorough explanation. Sadly for me the image is still not displayed within the {{% tab %}}. It works when I use it like {{< tab >}}, but other markdown code is not rendered. With which hugo version are you testing it on your side? This is the only difference we could have now.
Just to make sure we’re testing the same thing…
Last commit: 9096955798185a58a64da576a130f691f116aee6
I cannot reproduce what you’re seeing with v0.116.0 or later.
In v0.116.0, we updated the markdown renderer (Goldmark) from v1.5.4 to v1.5.5, which fixed https://github.com/yuin/goldmark/issues/406, which I’m pretty sure is the bug you’re seeing.
So, use Hugo v0.116.0 or later, preferably the latest release, v0.121.2.