Repository: gohugoio/hugo (language: go)

Issue:
Error "unknown shortcode token" when calling shortcode within fenced code block
**N.B. I'm not sure if this is a bug, or if we've fixed a bug.**

Reproducible with v0.111.0 and later.

If a shortcode is called using the `{{< >}}` notation within a fenced code block, Chroma lexes the placeholder, triggering an error such as:

> unknown shortcode token "HAHAHUGOSHORTCODE</span><span style=\"color:#f92672\">-</span><span style=\"color:#a6e22e\">s0</span><span style=\"color:#f92672\">-</span><span style=\"color:#a6e22e\">HBHB"

But this does not happen with all lexers, and may depend on where the shortcode is placed within the codeblock (not sure).

For example, this works:

````text
```bash
{{< sc >}}
```
````

But this throws an error:

````text
```go
{{< sc >}}
```
````

And both of these work:

````text
```bash
{{% sc %}}
```

```go
{{% sc %}}
```
````

What the shortcode does is irrelevant (e.g., it can be empty).

Reference: <https://discourse.gohugo.io/t/43387>  (Kubernetes site)

Simple example:

```text
git clone --single-branch -b hugo-forum-topic-43387 https://github.com/jmooring/hugo-testing hugo-forum-topic-43387
cd hugo-forum-topic-43387
hugo server
```


Discussion / hints:

Fix patch:
diff --git a/hugolib/shortcode.go b/hugolib/shortcode.go
index 1c0dfaade1b..c12fb888b06 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 {


Test patch:
diff --git a/hugolib/shortcode_test.go b/hugolib/shortcode_test.go
index 67c83f44e45..998608a55b8 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>")
+
+}