]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Fix "unknown shortcode token" when calling shortcode within fenced code block
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 12 Mar 2023 09:50:16 +0000 (10:50 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 12 Mar 2023 10:39:38 +0000 (11:39 +0100)
Fixes #10819

hugolib/shortcode.go
hugolib/shortcode_test.go

index 1c0dfaade1b49bdccc8b1bff3fc4ffd3aff3ebc9..c12fb888b06a8d9b6c49a288b7a27d55f69d15c2 100644 (file)
@@ -186,7 +186,7 @@ func (scp *ShortcodeWithPage) page() page.Page {
 const shortcodePlaceholderPrefix = "HAHAHUGOSHORTCODE"
 
 func createShortcodePlaceholder(id string, ordinal int) string {
-       return shortcodePlaceholderPrefix + "-" + id + strconv.Itoa(ordinal) + "-HBHB"
+       return shortcodePlaceholderPrefix + id + strconv.Itoa(ordinal) + "HBHB"
 }
 
 type shortcode struct {
index 67c83f44e45987ad7dbf0c3c9ab5cb529fd4f95a..998608a55b8c37278f288ef648cff9a7d7f79085 100644 (file)
@@ -1276,3 +1276,40 @@ Inner: {{ .Get 0 }}: {{ len .Inner }}
        b.Assert(err, qt.Not(qt.IsNil))
        b.Assert(err.Error(), qt.Contains, `p1.md:5:1": failed to extract shortcode: shortcode "sc" must be closed or self-closed`)
 }
+
+// Issue 10819.
+func TestShortcodeInCodeFenceHyphen(t *testing.T) {
+       t.Parallel()
+
+       files := `
+-- config.toml --
+disableKinds = ["home", "taxonomy", "term"]
+-- content/p1.md --
+---
+title: "p1"
+---
+
+§§§go
+{{< sc >}}
+§§§
+
+Text.
+
+-- layouts/shortcodes/sc.html --
+Hello.
+-- layouts/_default/single.html --
+{{ .Content }}
+`
+
+       b := NewIntegrationTestBuilder(
+               IntegrationTestConfig{
+                       T:           t,
+                       TxtarString: files,
+                       Running:     true,
+                       Verbose:     true,
+               },
+       ).Build()
+
+       b.AssertFileContent("public/p1/index.html", "<span style=\"color:#a6e22e\">Hello.</span>")
+
+}