]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
tpl: Fix it so we always prefer internal codeblock rendering over render-codeblock...
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 25 Apr 2025 06:31:26 +0000 (08:31 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 25 Apr 2025 08:51:33 +0000 (10:51 +0200)
Fixes #13651

tpl/tplimpl/templatedescriptor.go
tpl/tplimpl/templatestore_integration_test.go

index f65ad3943104fc444785a2f084a3c5c08c15edc9..ea47afc88d3407d5fe3f6a8d96691deedf8fd039 100644 (file)
@@ -130,17 +130,12 @@ func (this TemplateDescriptor) doCompare(category Category, isEmbedded bool, def
 
        // One example of variant1 and 2 is for render codeblocks:
        // variant1=codeblock, variant2=go (language).
-       if other.Variant1 != "" && other.Variant1 != this.Variant1 {
-               return w
-       }
-
-       if isEmbedded {
-               if other.Variant2 != "" && other.Variant2 != this.Variant2 {
+       if other.Variant1 != "" {
+               if other.Variant1 != this.Variant1 {
                        return w
                }
-       } else {
-               // If both are set and different, no match.
-               if other.Variant2 != "" && this.Variant2 != "" && other.Variant2 != this.Variant2 {
+
+               if other.Variant2 != "" && other.Variant2 != this.Variant2 {
                        return w
                }
        }
index bd00f82b7b2d303b2b8c2b106b984da4a575704b..638341581d9bc473611c74cc5eea5e8ec43fd9c1 100644 (file)
@@ -1038,6 +1038,35 @@ _markup/render-codeblock-goat.html
        b.AssertFileContent("public/index.html", "_markup/render-codeblock.html_markup/render-codeblock-goat.html")
 }
 
+func TestLookupCodeblockIssue13651(t *testing.T) {
+       t.Parallel()
+
+       files := `
+-- hugo.toml --
+-- layouts/all.html --
+{{ .Content }}|
+-- layouts/_markup/render-codeblock-foo.html --
+render-codeblock-foo.html
+-- content/_index.md --
+---
+---
+
+§§§
+printf "Hello, world!"
+§§§
+
+§§§ foo
+printf "Hello, world again!"
+§§§
+`
+
+       b := hugolib.Test(t, files)
+
+       content := b.FileContent("public/index.html")
+       fooCount := strings.Count(content, "render-codeblock-foo.html")
+       b.Assert(fooCount, qt.Equals, 1)
+}
+
 // Issue #13515
 func TestPrintPathWarningOnDotRemoval(t *testing.T) {
        t.Parallel()