summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-03-12 10:50:16 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-03-12 11:39:38 +0100
commite7148f335fabf0170b8158d39cd2ea95bc04fd7e (patch)
tree0f9bfe0c86a3758b98e89d212bb0d888187a496c
parentd55af2abf0548e627998d3905cfdec5b7b8f7ec3 (diff)
Fix "unknown shortcode token" when calling shortcode within fenced code block
Fixes #10819
-rw-r--r--hugolib/shortcode.go2
-rw-r--r--hugolib/shortcode_test.go37
2 files changed, 38 insertions, 1 deletions
diff --git a/hugolib/shortcode.go b/hugolib/shortcode.go
index 1c0dfaade..c12fb888b 100644
--- a/hugolib/shortcode.go
+++ b/hugolib/shortcode.go
@@ -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 {
diff --git a/hugolib/shortcode_test.go b/hugolib/shortcode_test.go
index 67c83f44e..998608a55 100644
--- a/hugolib/shortcode_test.go
+++ b/hugolib/shortcode_test.go
@@ -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>")
+
+}