mirror of
https://github.com/gohugoio/hugo.git
synced 2026-08-24 15:28:54 +00:00
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user