`)
}
+
+// https://github.com/gohugoio/hugo/issues/6882
+func TestRenderStringOnListPage(t *testing.T) {
+ renderStringTempl := `
+{{ .RenderString "**Hello**" }}
+`
+ b := newTestSitesBuilder(t)
+ b.WithContent("mysection/p1.md", `FOO`)
+ b.WithTemplates(
+ "index.html", renderStringTempl,
+ "_default/list.html", renderStringTempl,
+ "_default/single.html", renderStringTempl,
+ )
+
+ b.Build(BuildCfg{})
+
+ for _, filename := range []string{
+ "index.html",
+ "mysection/index.html",
+ "categories/index.html",
+ "tags/index.html",
+ "mysection/p1/index.html",
+ } {
+ b.AssertFileContent("public/"+filename, `<strong>Hello</strong>`)
+ }
+
+}
}
func (p *pageState) getContentConverter() converter.Converter {
+ var err error
+ p.m.contentConverterInit.Do(func() {
+ markup := p.m.markup
+ if markup == "html" {
+ // Only used for shortcode inner content.
+ markup = "markdown"
+ }
+ p.m.contentConverter, err = p.m.newContentConverter(p, markup, p.m.renderingConfigOverrides)
+
+ })
+
+ if err != nil {
+ p.s.Log.ERROR.Println("Failed to create content converter:", err)
+ }
return p.m.contentConverter
}
"path/filepath"
"regexp"
"strings"
+ "sync"
"time"
"github.com/gohugoio/hugo/markup/converter"
s *Site
- contentConverter converter.Converter
+ renderingConfigOverrides map[string]interface{}
+ contentConverterInit sync.Once
+ contentConverter converter.Converter
}
func (p *pageMeta) Aliases() []string {
renderingConfigOverrides = maps.ToStringMap(bfParam)
}
- markup := p.markup
- if markup == "html" {
- // Only used for shortcode inner content.
- markup = "markdown"
- }
+ p.renderingConfigOverrides = renderingConfigOverrides
- cp, err := p.newContentConverter(n.p, markup, renderingConfigOverrides)
- if err != nil {
- return err
- }
- p.contentConverter = cp
}
return nil
}
cp := p.s.ContentSpec.Converters.Get(markup)
if cp == nil {
- return nil, errors.Errorf("no content renderer found for markup %q", p.markup)
+ return converter.NopConverter, errors.Errorf("no content renderer found for markup %q", p.markup)
}
cpp, err := cp.New(
)
if err != nil {
- return nil, err
+ return converter.NopConverter, err
}
return cpp, nil
package converter
import (
+ "bytes"
+
"github.com/gohugoio/hugo/common/loggers"
"github.com/gohugoio/hugo/config"
"github.com/gohugoio/hugo/identity"
return n.name
}
+var NopConverter = new(nopConverter)
+
+type nopConverter int
+
+func (nopConverter) Convert(ctx RenderContext) (Result, error) {
+ return &bytes.Buffer{}, nil
+}
+
+func (nopConverter) Supports(feature identity.Identity) bool {
+ return false
+}
+
// Converter wraps the Convert method that converts some markup into
// another format, e.g. Markdown to HTML.
type Converter interface {