Skip to content

Commit

Permalink
Fix "unknown shortcode token" when calling shortcode within fenced co…
Browse files Browse the repository at this point in the history
…de block

Fixes #10819
  • Loading branch information
bep committed Mar 12, 2023
1 parent d55af2a commit e7148f3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion hugolib/shortcode.go
Expand Up @@ -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 {
Expand Down
37 changes: 37 additions & 0 deletions hugolib/shortcode_test.go
Expand Up @@ -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>")

}

0 comments on commit e7148f3

Please sign in to comment.