<figure {{ with .Get "class" }}class="{{.}}"{{ end }}>

    {{ with .Get "align" }}<div align="{{.}}">{{ end }}
        {{ with .Get "href" }}<a href="{{.}}">{{ end }}
            <img src="{{ or (.Get "src") (.Get 0) }}"
                {{ with .Get "class" }}class="{{.}}"{{ end }}
                {{ if or (.Get "alt") (.Get "caption") }}
                    alt="{{ with .Get "alt"}}{{.}}{{else}}{{ .Get "caption" }}{{ end }}"
                {{ end }}
                {{ with .Get "width" }}width="{{.}}"{{ end }}
                {{ with .Get "height" }}height="{{.}}"{{ end }}
                loading="lazy" decoding="async"
            />

            {{ if or (or (.Get "title") (.Get "caption")) (.Get "attr")}}
            <figcaption>
                {{ if isset .Params "title" }}<h4>{{ .Get "title" }}</h4>{{ end }}

                {{ if or (.Get "caption") (.Get "attr")}}
                        {{ .Get "caption" }}

                        {{ if isset .Params "attrlink"}}
                            {{ if isset .Params "align"}}
                            {{/*  we need the class here to remove margin-left for center alignment  */}}
                            <a class="{{.Get "align"}}" href="{{.Get "attrlink"}}">
                            {{ else }}
                            <a href="{{.Get "attrlink"}}">
                            {{ end }}
                        {{ end }}

                                {{ .Get "attr" }}

                            {{ if isset .Params "attrlink"}}</a>{{ end }}
                {{ end }}

            </figcaption>
            {{ end }}

    {{ if isset .Params "align" }}</div>{{ end }}
    {{ if isset .Params "href" }}</a>{{ end }}

</figure>
