Skip to content

Commit

Permalink
tpl/tplimpl: Honor markdown attributes in embedded image render hook
Browse files Browse the repository at this point in the history
Fixes #12203
  • Loading branch information
jmooring authored and bep committed Mar 7, 2024
1 parent b1de03f commit 632ad74
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Expand Up @@ -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 -}}
Expand Down
30 changes: 30 additions & 0 deletions tpl/tplimpl/render_hook_integration_test.go
Expand Up @@ -14,6 +14,7 @@
package tplimpl_test

import (
"strings"
"testing"

"github.com/gohugoio/hugo/hugolib"
Expand Down Expand Up @@ -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">`)
}

0 comments on commit 632ad74

Please sign in to comment.