import (
"bytes"
- "context"
"encoding/base64"
"errors"
"fmt"
"github.com/gohugoio/hugo/hugofs/hglob"
"github.com/gohugoio/hugo/hugolib/sitesmatrix"
"github.com/gohugoio/hugo/identity"
+ "github.com/gohugoio/hugo/media"
"github.com/spf13/afero"
- "github.com/spf13/cast"
"golang.org/x/text/unicode/norm"
"golang.org/x/tools/txtar"
)
func (s *IntegrationTestBuilder) AssertNoRenderShortcodesArtifacts() {
s.Helper()
- for _, p := range s.H.Pages() {
- content, err := p.Content(context.Background())
+ afero.Walk(s.fs.PublishDir, "", func(path string, info os.FileInfo, err error) error {
+ if err != nil || info.IsDir() {
+ return err
+ }
+ ext := strings.TrimPrefix(filepath.Ext(path), ".")
+ if !s.H.Conf.GetConfigSection("mediaTypes").(media.Types).IsTextSuffix(ext) {
+ return nil
+ }
+ content, err := afero.ReadFile(s.fs.PublishDir, path)
s.Assert(err, qt.IsNil)
- comment := qt.Commentf("Page: %s\n%s", p.Path(), content)
- s.Assert(strings.Contains(cast.ToString(content), "__hugo_ctx"), qt.IsFalse, comment)
- }
+ comment := qt.Commentf("File: %s\n%s", path, string(content))
+ s.Assert(strings.Contains(string(content), "__hugo_ctx"), qt.IsFalse, comment)
+ return nil
+ })
}
type IntegrationTestImageHelper struct {
return template.HTML(hugocontext.Wrap(cc, pco.po.p.pid)), nil
}
+ // Strip any Hugo context markers from nested RenderShortcodes calls
+ // that won't be processed by Goldmark.
+ cc = hugocontext.Strip(cc)
+
return helpers.BytesToHTML(cc), nil
}
"<p>a</p>\n<p><em>emphasized</em></p>\n<p>not emphasized</p>\n<p>b</p>\n",
)
}
+
+// Issue 14732.
+func TestRenderShortcodesStandalone(t *testing.T) {
+ t.Parallel()
+
+ files := `
+-- hugo.toml --
+disableKinds = ['section','rss','sitemap','taxonomy','term']
+-- layouts/all.html --
+RenderShortcodes: {{ .RenderShortcodes }}|
+-- layouts/_shortcodes/headings.html --
+## Heading 1
+### Heading 2
+{{ $p := site.GetPage "includeme" }}
+RenderShortcodes2: {{ $p.RenderShortcodes }}|
+-- content/p1.md --
+---
+title: "p1"
+---
+{{% headings "headings" %}}
+-- content/includeme.md --
+---
+title: "includeme"
+---
+## Heading 2
+`
+
+ b := Test(t, files)
+
+ b.AssertNoRenderShortcodesArtifacts()
+}
hugoCtxRe = regexp.MustCompile(`{{__hugo_ctx( pid=\d+)?/?}}\n?`)
)
+// Strip strips any Hugo context markers from b.
+func Strip(b []byte) []byte {
+ if !bytes.Contains(b, hugoCtxPrefix) {
+ return b
+ }
+ return hugoCtxRe.ReplaceAll(b, nil)
+}
+
var _ parser.InlineParser = (*hugoContextParser)(nil)
type hugoContextParser struct{}