mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-12 10:25:44 +00:00
parent
32344fe3db
commit
9698b0dab1
4 changed files with 35 additions and 18 deletions
|
@ -364,9 +364,10 @@ func TestRenderString(t *testing.T) {
|
||||||
RSTART:{{ "**Bold Markdown**" | $p.RenderString }}:REND
|
RSTART:{{ "**Bold Markdown**" | $p.RenderString }}:REND
|
||||||
RSTART:{{ "**Bold Block Markdown**" | $p.RenderString $optBlock }}:REND
|
RSTART:{{ "**Bold Block Markdown**" | $p.RenderString $optBlock }}:REND
|
||||||
RSTART:{{ "/italic org mode/" | $p.RenderString $optOrg }}:REND
|
RSTART:{{ "/italic org mode/" | $p.RenderString $optOrg }}:REND
|
||||||
|
RSTART:{{ "## Header2" | $p.RenderString }}:REND
|
||||||
|
|
||||||
|
|
||||||
`)
|
`, "_default/_markup/render-heading.html", "Hook Heading: {{ .Level }}")
|
||||||
|
|
||||||
b.WithContent("p1.md", `---
|
b.WithContent("p1.md", `---
|
||||||
title: "p1"
|
title: "p1"
|
||||||
|
@ -380,6 +381,7 @@ title: "p1"
|
||||||
RSTART:<strong>Bold Markdown</strong>:REND
|
RSTART:<strong>Bold Markdown</strong>:REND
|
||||||
RSTART:<p><strong>Bold Block Markdown</strong></p>
|
RSTART:<p><strong>Bold Block Markdown</strong></p>
|
||||||
RSTART:<em>italic org mode</em>:REND
|
RSTART:<em>italic org mode</em>:REND
|
||||||
|
RSTART:Hook Heading: 2:REND
|
||||||
`)
|
`)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -604,6 +604,10 @@ func (p *pageState) RenderString(args ...interface{}) (template.HTML, error) {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err = p.pageOutput.initRenderHooks(); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
conv := p.getContentConverter()
|
conv := p.getContentConverter()
|
||||||
if opts.Markup != "" && opts.Markup != p.m.markup {
|
if opts.Markup != "" && opts.Markup != p.m.markup {
|
||||||
var err error
|
var err error
|
||||||
|
|
|
@ -96,24 +96,28 @@ func (o *pageOutput) initRenderHooks() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var initErr error
|
||||||
|
|
||||||
|
o.cp.renderHooks.init.Do(func() {
|
||||||
ps := o.cp.p
|
ps := o.cp.p
|
||||||
|
|
||||||
c := ps.getContentConverter()
|
c := ps.getContentConverter()
|
||||||
if c == nil || !c.Supports(converter.FeatureRenderHooks) {
|
if c == nil || !c.Supports(converter.FeatureRenderHooks) {
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
h, err := ps.createRenderHooks(o.f)
|
h, err := ps.createRenderHooks(o.f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
initErr = err
|
||||||
}
|
}
|
||||||
if h == nil {
|
if h == nil {
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
o.cp.renderHooks = h
|
o.cp.renderHooks.hooks = h
|
||||||
|
})
|
||||||
|
|
||||||
return nil
|
return initErr
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,6 +77,7 @@ func newPageContentOutput(p *pageState, po *pageOutput) (*pageContentOutput, err
|
||||||
dependencyTracker: dependencyTracker,
|
dependencyTracker: dependencyTracker,
|
||||||
p: p,
|
p: p,
|
||||||
f: po.f,
|
f: po.f,
|
||||||
|
renderHooks: &renderHooks{},
|
||||||
}
|
}
|
||||||
|
|
||||||
initContent := func() (err error) {
|
initContent := func() (err error) {
|
||||||
|
@ -227,6 +228,11 @@ func newPageContentOutput(p *pageState, po *pageOutput) (*pageContentOutput, err
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type renderHooks struct {
|
||||||
|
hooks *hooks.Renderers
|
||||||
|
init sync.Once
|
||||||
|
}
|
||||||
|
|
||||||
// pageContentOutput represents the Page content for a given output format.
|
// pageContentOutput represents the Page content for a given output format.
|
||||||
type pageContentOutput struct {
|
type pageContentOutput struct {
|
||||||
f output.Format
|
f output.Format
|
||||||
|
@ -244,8 +250,8 @@ type pageContentOutput struct {
|
||||||
placeholdersEnabled bool
|
placeholdersEnabled bool
|
||||||
placeholdersEnabledInit sync.Once
|
placeholdersEnabledInit sync.Once
|
||||||
|
|
||||||
// May be nil.
|
renderHooks *renderHooks
|
||||||
renderHooks *hooks.Renderers
|
|
||||||
// Set if there are more than one output format variant
|
// Set if there are more than one output format variant
|
||||||
renderHooksHaveVariants bool // TODO(bep) reimplement this in another way, consolidate with shortcodes
|
renderHooksHaveVariants bool // TODO(bep) reimplement this in another way, consolidate with shortcodes
|
||||||
|
|
||||||
|
@ -285,6 +291,7 @@ func (p *pageContentOutput) Reset() {
|
||||||
}
|
}
|
||||||
p.initMain.Reset()
|
p.initMain.Reset()
|
||||||
p.initPlain.Reset()
|
p.initPlain.Reset()
|
||||||
|
p.renderHooks = &renderHooks{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *pageContentOutput) Content() (interface{}, error) {
|
func (p *pageContentOutput) Content() (interface{}, error) {
|
||||||
|
@ -377,7 +384,7 @@ func (cp *pageContentOutput) renderContentWithConverter(c converter.Converter, c
|
||||||
converter.RenderContext{
|
converter.RenderContext{
|
||||||
Src: content,
|
Src: content,
|
||||||
RenderTOC: renderTOC,
|
RenderTOC: renderTOC,
|
||||||
RenderHooks: cp.renderHooks,
|
RenderHooks: cp.renderHooks.hooks,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue