Fix RenderShortcodes leaking context markers when indented

Strip leading whitespace from Hugo context marker lines before
Goldmark parsing to prevent them from being treated as indented
code blocks.

Fixes #12457

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Bjørn Erik Pedersen
2026-04-07 21:02:27 +02:00
parent 45e4596630
commit 161d0d4757
3 changed files with 41 additions and 0 deletions
@@ -102,8 +102,18 @@ var (
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) {