Skip to content

Commit 07983e0

Browse files
committed
tpl: Fix it so we always prefer internal codeblock rendering over render-codeblock-foo.html and similar
Fixes #13651
1 parent 5c49140 commit 07983e0

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

tpl/tplimpl/templatedescriptor.go

+4-9
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,12 @@ func (this TemplateDescriptor) doCompare(category Category, isEmbedded bool, def
130130

131131
// One example of variant1 and 2 is for render codeblocks:
132132
// variant1=codeblock, variant2=go (language).
133-
if other.Variant1 != "" && other.Variant1 != this.Variant1 {
134-
return w
135-
}
136-
137-
if isEmbedded {
138-
if other.Variant2 != "" && other.Variant2 != this.Variant2 {
133+
if other.Variant1 != "" {
134+
if other.Variant1 != this.Variant1 {
139135
return w
140136
}
141-
} else {
142-
// If both are set and different, no match.
143-
if other.Variant2 != "" && this.Variant2 != "" && other.Variant2 != this.Variant2 {
137+
138+
if other.Variant2 != "" && other.Variant2 != this.Variant2 {
144139
return w
145140
}
146141
}

tpl/tplimpl/templatestore_integration_test.go

+29
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,35 @@ _markup/render-codeblock-goat.html
10381038
b.AssertFileContent("public/index.html", "_markup/render-codeblock.html_markup/render-codeblock-goat.html")
10391039
}
10401040

1041+
func TestLookupCodeblockIssue13651(t *testing.T) {
1042+
t.Parallel()
1043+
1044+
files := `
1045+
-- hugo.toml --
1046+
-- layouts/all.html --
1047+
{{ .Content }}|
1048+
-- layouts/_markup/render-codeblock-foo.html --
1049+
render-codeblock-foo.html
1050+
-- content/_index.md --
1051+
---
1052+
---
1053+
1054+
§§§
1055+
printf "Hello, world!"
1056+
§§§
1057+
1058+
§§§ foo
1059+
printf "Hello, world again!"
1060+
§§§
1061+
`
1062+
1063+
b := hugolib.Test(t, files)
1064+
1065+
content := b.FileContent("public/index.html")
1066+
fooCount := strings.Count(content, "render-codeblock-foo.html")
1067+
b.Assert(fooCount, qt.Equals, 1)
1068+
}
1069+
10411070
// Issue #13515
10421071
func TestPrintPathWarningOnDotRemoval(t *testing.T) {
10431072
t.Parallel()

0 commit comments

Comments
 (0)