diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-01-26 10:30:25 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-01-26 11:41:07 +0100 |
commit | 168858331f5e9311e718410e55c4296313ce6b05 (patch) | |
tree | f15001a545c3015e688c4296f5c349b8b3da16c0 /hugolib | |
parent | 4ef9baf5bd24b6a105f78eba1147dad9ffabd82a (diff) |
Fix shortcode detection in RenderString
Fixes #10654
Diffstat (limited to 'hugolib')
-rw-r--r-- | hugolib/page__per_output.go | 4 | ||||
-rw-r--r-- | hugolib/renderstring_test.go | 36 |
2 files changed, 38 insertions, 2 deletions
diff --git a/hugolib/page__per_output.go b/hugolib/page__per_output.go index 60e3a7f59..97e9cc465 100644 --- a/hugolib/page__per_output.go +++ b/hugolib/page__per_output.go @@ -384,8 +384,8 @@ func (p *pageContentOutput) RenderString(args ...any) (template.HTML, error) { var rendered []byte - if strings.Contains(contentToRender, "{{") { - // Probably a shortcode. + if pageparser.HasShortcode(contentToRender) { + // String contains a shortcode. parsed, err := pageparser.ParseMain(strings.NewReader(contentToRender), pageparser.Config{}) if err != nil { return "", err diff --git a/hugolib/renderstring_test.go b/hugolib/renderstring_test.go index 1be0cdffb..af66156e6 100644 --- a/hugolib/renderstring_test.go +++ b/hugolib/renderstring_test.go @@ -190,3 +190,39 @@ Has other: false `) } + +func TestRenderStringWithShortcodeIssue10654(t *testing.T) { + t.Parallel() + + files := ` +-- config.toml -- +timeout = '300ms' +-- content/p1.md -- +--- +title: "P1" +--- +{{< toc >}} + +## Heading 1 + +{{< noop >}} + {{ not a shortcode +{{< /noop >}} +} +-- layouts/shortcodes/noop.html -- +{{ .Inner | $.Page.RenderString }} +-- layouts/shortcodes/toc.html -- +{{ .Page.TableOfContents }} +-- layouts/_default/single.html -- +{{ .Content }} +` + + b := NewIntegrationTestBuilder( + IntegrationTestConfig{ + T: t, + TxtarString: files, + }, + ).Build() + + b.AssertFileContent("public/p1/index.html", `TableOfContents`) +} |