In a content file if a markdown syntax image is specified in the form of ![image](/image.jpg)
and there is text above it like so:
Lorem Ipsum
![image](/image.jpg)
Then said image will not be processed by Goldmark.
To make it processed one will have to enter a newline like so:
Lorem Ipsum
![image](/image.jpg)
Then the image will be processed by Goldmark but also an empty <p></p>
tag will be outputted that cannot be removed no matter what.
In the past (with Blackfriday) I used to get rid of the empty <p>
tags with something like:
{{ replace .Content "<p></p>" "" | safeHTML }}
Unfortunately this does not seem possible anymore.
Any ideas?
cc: @bep
Well… I will be damned.
Turns out that I encountered the above behavior because right above the text there was a shortcode with the <>
delimiters like so:
{{< img src="image.jpg" alt="Some image" >}}
Lorem Ipsum
![image](/image.jpg)
In the above scenario the markdown image is not processed like I mentioned above but if I change the shortcode delimiters to %
instead like so:
{{% img src="another-image.jpg" alt="Some other image" %}}
Lorem Ipsum
![image](/image.jpg)
Then the markdown image will be processed.
Don’t know if this qualifies as a bug or not but @bep should know about it.
Also both an image shortcode and a markdown render-image hook are used, because I am working with a complex layout and there are different templates for each.
Anyway this was the new thing I found out about Hugo today.
On a side note: If you like working on the shell I suggest having a look at a tool called “remark”. It has a powerful linter that checks your markdown files and forces you to write “proper” markdown. There is even a plugin that adds some rules that make your markdown even more stable between various compilers. I added that and removed the hacks (like the config-goldmark-unsafe rule).
It’s a bit of a hassle to set up properly, I could share my config.
1 Like
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.