10000 Fix "unknown shortcode token" when calling shortcode within fenced co… · gohugoio/hugo@e7148f3 · GitHub
[go: up one dir, main page]

Skip to content

Commit e7148f3

Browse files
committed
Fix "unknown shortcode token" when calling shortcode within fenced code block
Fixes #10819
1 parent d55af2a commit e7148f3

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

hugolib/shortcode.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func (scp *ShortcodeWithPage) page() page.Page {
186186
const shortcodePlaceholderPrefix = "HAHAHUGOSHORTCODE"
187187

188188
func createShortcodePlaceholder(id string, ordinal int) string {
189-
return shortcodePlaceholderPrefix + "-" + id + strconv.Itoa(ordinal) + "-HBHB"
189+
return shortcodePlaceholderPrefix + id + strconv.Itoa(ordinal) + "HBHB"
190190
}
191191

192192
type shortcode struct {

hugolib/shortcode_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,3 +1276,40 @@ Inner: {{ .Get 0 }}: {{ len .Inner }}
12761276
b.Assert(err, qt.Not(qt.IsNil))
12771277
b.Assert(err.Error(), qt.Contains, `p1.md:5:1": failed to extract shortcode: shortcode "sc" must be closed or self-closed`)
12781278
}
1279+
1280+
// Issue 10819.
1281+
func TestShortcodeInCodeFenceHyphen(t *testing.T) {
1282+
t.Parallel()
1283+
1284+
files := `
1285+
-- config.toml --
1286+
disableKinds = ["home", "taxonomy", "term"]
1287+
-- content/p1.md --
1288+
---
1289+
title: "p1"
1290+
---
1291+
1292+
§§§go
1293+
{{< sc >}}
1294+
§§§
1295+
1296+
Text.
1297+
1298+
-- layouts/shortcodes/sc.html --
1299+
Hello.
1300+
-- layouts/_default/single.html --
1301+
{{ .Content }}
1302+
`
1303+
1304+
b := NewIntegrationTestBuilder(
1305+
IntegrationTestConfig{
1306+
T: t,
1307+
TxtarString: files,
1308+
Running: true,
1309+
Verbose: true,
1310+
},
1311+
).Build()
1312+
1313+
b.AssertFileContent("public/p1/index.html", "<span style=\"color:#a6e22e\">Hello.</span>")
1314+
1315+
}

0 commit comments

Comments
 (0)
0