As per the Doc you linked to above attribute is not available for Markdown images. You can only pass a class through the title as you’ve already done.
attribute
Enable custom attribute support for titles and blocks by adding attribute lists inside single curly brackets ( {.myclass class="class1 class2" } ) and placing it after the Markdown element it decorates , on the same line for titles and on a new line directly below for blocks.
You could also insert raw HTML in your Markdown like this:
<div class="color-main">
![/img/pathhere.jpg](This is a photo of stuff)
</div>
For that, you need to allow HTML rendering in .md files with the following lines in config.toml:
[markup.goldmark.renderer]
unsafe = true
(about the ‘unsafe’ param: the wording is a bit over-worrying here, you can use it safely AFAIK, especially if you are the only one with the push permission for your repo)
All right thank you both (iaeiou) and (onedrawingperday), so with the various resources and blogs around the net, I did the below (finally confronting it this morning).
The Lead here is probably going call me crazy, but it might have merit and does work:
So, I want to have the markdown for non-foundational content to be the most clean I could possibly get, and where this solution wouldn’t be what I call “elegant” it does handle, fully, captions, class passing, clean URLs, Titles and alt tags:
So, I have the below in Layouts/_default/_markup/render-image.html
{{ $class := index ( findRE “\?(.?)\?" .Destination ) 0 }}
{{ $cleanClass := replace $class “?” “” }}
{{ $destination := index ( findRE "^(.?)\?” .Destination ) 0 }}
{{ $cleanDestination := replace $destination “?” “” }}
{{ $caption := index ( findRE “\#(.*?)\#” .Destination ) 0 }}
And Mr. Mooring, that’s a three-peat kind-sir.
But, iaseiou and Mr. Mooring, - this is interesting, if there was a way to capture that “Your Caption” (within hugo) with a render-template through a variable (like {.Title}) then that would be fantastic. It would mean my hack could be a little simpler.
So, as far as I know, am image has {{.Title}} {{.Destination}} is there something like {{.caption}} which would give me the your caption so I can then make it semantically correct within the <figcaption></figcaption>
If their is a way you could help me shed light on such?
A <figure> is a block element. An <img> is an inline element. If you try to use an image render hook to return a <figure>, the <figure> will be treated as inline element.
Bottom line: if you want to place a <figure> in your content, use the built-in figure shortcode or roll your own.