]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
tpl/tplimpl: Honor markdown attributes in embedded image render hook
authorJoe Mooring <joe.mooring@veriphor.com>
Wed, 6 Mar 2024 00:06:50 +0000 (16:06 -0800)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 7 Mar 2024 07:21:58 +0000 (08:21 +0100)
Fixes #12203

tpl/tplimpl/embedded/templates/_default/_markup/render-image.html
tpl/tplimpl/render_hook_integration_test.go

index c90ababd2248d6e05e3cec214fe198eb42512653..fa78cd00c15a8c58a21f5f180bab535de9161fc0 100644 (file)
@@ -5,7 +5,7 @@
     {{- $src = .RelPermalink -}}
   {{- end -}}
 {{- end -}}
-{{- $attributes := dict "alt" .Text "src" $src "title" .Title -}}
+{{- $attributes := merge .Attributes (dict "alt" .Text "src" $src "title" .Title) -}}
 <img
   {{- range $k, $v := $attributes -}}
     {{- if $v -}}
index 607e06059cc231277b8ac4d4ab167420da77e375..07c24108d5458272df69384d916ffecf33c85c1d 100644 (file)
@@ -14,6 +14,7 @@
 package tplimpl_test
 
 import (
+       "strings"
        "testing"
 
        "github.com/gohugoio/hugo/hugolib"
@@ -127,3 +128,32 @@ title: s1/p3
                `<a href="/s1/p2/b.txt">600</a>`,
        )
 }
+
+// Issue 12203
+func TestEmbeddedImageRenderHookMarkdownAttributes(t *testing.T) {
+       t.Parallel()
+
+       files := `
+-- config.toml --
+disableKinds = ['page','rss','section','sitemap','taxonomy','term']
+[markup.goldmark.parser]
+wrapStandAloneImageWithinParagraph = false
+[markup.goldmark.parser.attribute]
+block = false
+[markup.goldmark.renderHooks.image]
+enableDefault = true
+-- content/_index.md --
+![alt](a.jpg)
+{.foo #bar}
+-- layouts/index.html --
+{{ .Content }}
+`
+
+       b := hugolib.Test(t, files)
+       b.AssertFileContent("public/index.html", `<img alt="alt" src="a.jpg">`)
+
+       files = strings.Replace(files, "block = false", "block = true", -1)
+
+       b = hugolib.Test(t, files)
+       b.AssertFileContent("public/index.html", `<img alt="alt" class="foo" id="bar" src="a.jpg">`)
+}