b.AssertNoRenderShortcodesArtifacts()
}
+
+// Issue 12457.
+func TestRenderShortcodesCodeBlock(t *testing.T) {
+ t.Parallel()
+
+ files := `
+-- hugo.toml --
+disableKinds = ['section','rss','sitemap','taxonomy','term']
+-- layouts/_shortcodes/foo.html --
+{{ $p := site.GetPage "includeme" }}
+ {{ $p.RenderShortcodes }}
+-- layouts/home.html --
+{{ .Content }}
+-- content/_index.md --
+---
+title: home
+---
+{{% foo %}}
+-- content/includeme.md --
+---
+title: "includeme"
+---
+Some markdown.
+ `
+
+ b := Test(t, files)
+ b.AssertNoRenderShortcodesArtifacts()
+ b.AssertFileContentEquals("public/index.html", "<p>Some markdown.</p>\n")
+}
hugoCtxEndDelim = []byte("}}")
hugoCtxClosingDelim = []byte("/}}")
hugoCtxRe = regexp.MustCompile(`{{__hugo_ctx( pid=\d+)?/?}}\n?`)
+ hugoCtxIndentedRe = regexp.MustCompile(`(?m)^[ \t]+({{__hugo_ctx[^\n]*}})`)
)
+// DedentMarkers removes leading whitespace from Hugo context marker lines
+// to prevent them from being treated as indented code blocks by Goldmark.
+func DedentMarkers(b []byte) []byte {
+ if !bytes.Contains(b, hugoCtxPrefix) {
+ return b
+ }
+ return hugoCtxIndentedRe.ReplaceAll(b, []byte("$1"))
+}
+
// Strip strips any Hugo context markers from b.
func Strip(b []byte) []byte {
if !bytes.Contains(b, hugoCtxPrefix) {