tpl/tplimpl: Use plain text for image render hook alt attribute

Co-authored-by: Heracles <email@heracl.es>
This commit is contained in:
Joe Mooring 2025-01-09 23:36:10 -08:00 committed by Bjørn Erik Pedersen
parent dde9d9d544
commit 8af04745fb
3 changed files with 10 additions and 6 deletions

View file

@ -246,9 +246,10 @@ iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAA
func TestRenderHooksDefaultEscape(t *testing.T) { func TestRenderHooksDefaultEscape(t *testing.T) {
files := ` files := `
-- hugo.toml -- -- hugo.toml --
[markup.goldmark.renderHooks] [markup.goldmark.extensions.typographer]
disable = true
[markup.goldmark.renderHooks.image] [markup.goldmark.renderHooks.image]
enableDefault = ENABLE enableDefault = ENABLE
[markup.goldmark.renderHooks.link] [markup.goldmark.renderHooks.link]
enableDefault = ENABLE enableDefault = ENABLE
[markup.goldmark.parser] [markup.goldmark.parser]
@ -256,6 +257,7 @@ wrapStandAloneImageWithinParagraph = false
[markup.goldmark.parser.attribute] [markup.goldmark.parser.attribute]
block = true block = true
title = true title = true
-- content/_index.md -- -- content/_index.md --
--- ---
title: "Home" title: "Home"
@ -279,7 +281,7 @@ Image: ![alt-"<>&](/destination-"<> 'title-"<>&')
if enabled { if enabled {
b.AssertFileContent("public/index.html", b.AssertFileContent("public/index.html",
"Link: <a href=\"/destination-%22%3C%3E\" title=\"title-&#34;&lt;&gt;&amp;\">text-&quot;&lt;&gt;&amp;</a>", "Link: <a href=\"/destination-%22%3C%3E\" title=\"title-&#34;&lt;&gt;&amp;\">text-&quot;&lt;&gt;&amp;</a>",
"img src=\"/destination-%22%3C%3E\" alt=\"alt-&quot;&lt;&gt;&amp;\" title=\"title-&#34;&lt;&gt;&amp;\">", "img src=\"/destination-%22%3C%3E\" alt=\"alt-&#34;&lt;&gt;&amp;\" title=\"title-&#34;&lt;&gt;&amp;\">",
"&gt;&lt;script&gt;", "&gt;&lt;script&gt;",
) )
} else { } else {

View file

@ -12,7 +12,7 @@
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}
<img src="{{ $src }}" alt="{{ .Text }}" <img src="{{ $src }}" alt="{{ .PlainText }}"
{{- with .Title }} title="{{ . }}" {{- end -}} {{- with .Title }} title="{{ . }}" {{- end -}}
{{- range $k, $v := .Attributes -}} {{- range $k, $v := .Attributes -}}
{{- if $v -}} {{- if $v -}}

View file

@ -146,6 +146,8 @@ func TestEmbeddedImageRenderHook(t *testing.T) {
-- config.toml -- -- config.toml --
baseURL = 'https://example.org/dir/' baseURL = 'https://example.org/dir/'
disableKinds = ['home','rss','section','sitemap','taxonomy','term'] disableKinds = ['home','rss','section','sitemap','taxonomy','term']
[markup.goldmark.extensions.typographer]
disable = true
[markup.goldmark.parser] [markup.goldmark.parser]
wrapStandAloneImageWithinParagraph = false wrapStandAloneImageWithinParagraph = false
[markup.goldmark.parser.attribute] [markup.goldmark.parser.attribute]
@ -174,7 +176,7 @@ iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAA
b.AssertFileContent("public/p1/index.html", b.AssertFileContent("public/p1/index.html",
`<img src="" alt="">`, `<img src="" alt="">`,
`<img src="/dir/p1/pixel.png" alt="alt1">`, `<img src="/dir/p1/pixel.png" alt="alt1">`,
`<img src="/dir/p1/pixel.png" alt="alt2-&amp;&lt;&gt;&rsquo;" title="&amp;&lt;&gt;&#39;">`, `<img src="/dir/p1/pixel.png" alt="alt2-&amp;&lt;&gt;&#39;" title="&amp;&lt;&gt;&#39;">`,
`<img src="/dir/p1/pixel.png?a=b&amp;c=d#fragment" alt="alt3">`, `<img src="/dir/p1/pixel.png?a=b&amp;c=d#fragment" alt="alt3">`,
`<img src="/dir/p1/pixel.png" alt="alt4">`, `<img src="/dir/p1/pixel.png" alt="alt4">`,
) )
@ -185,7 +187,7 @@ iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAA
b.AssertFileContent("public/p1/index.html", b.AssertFileContent("public/p1/index.html",
`<img src="" alt="">`, `<img src="" alt="">`,
`<img src="/dir/p1/pixel.png" alt="alt1">`, `<img src="/dir/p1/pixel.png" alt="alt1">`,
`<img src="/dir/p1/pixel.png" alt="alt2-&amp;&lt;&gt;&rsquo;" title="&amp;&lt;&gt;&#39;">`, `<img src="/dir/p1/pixel.png" alt="alt2-&amp;&lt;&gt;&#39;" title="&amp;&lt;&gt;&#39;">`,
`<img src="/dir/p1/pixel.png?a=b&amp;c=d#fragment" alt="alt3" class="foo" id="bar">`, `<img src="/dir/p1/pixel.png?a=b&amp;c=d#fragment" alt="alt3" class="foo" id="bar">`,
`<img src="/dir/p1/pixel.png" alt="alt4" id="&#34;&gt;&lt;script&gt;alert()&lt;/script&gt;">`, `<img src="/dir/p1/pixel.png" alt="alt4" id="&#34;&gt;&lt;script&gt;alert()&lt;/script&gt;">`,
) )