diff options
author | Bjørn Erik Pedersen <[email protected]> | 2023-02-25 09:24:59 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2023-02-25 19:53:18 +0100 |
commit | ce524d0b5ebaef05d29fa368465f31358f26dcda (patch) | |
tree | e5df54a5deeefacbff4916d3619f85c2cb341b01 /markup | |
parent | 2662faf61ff0240be1ee0d6c496b6b4a6ed55fb4 (diff) | |
download | hugo-ce524d0b5ebaef05d29fa368465f31358f26dcda.tar.gz hugo-ce524d0b5ebaef05d29fa368465f31358f26dcda.zip |
Add a page template func
Fixes #9339
Diffstat (limited to 'markup')
-rw-r--r-- | markup/converter/converter.go | 4 | ||||
-rw-r--r-- | markup/converter/hooks/hooks.go | 7 | ||||
-rw-r--r-- | markup/goldmark/codeblocks/render.go | 1 | ||||
-rw-r--r-- | markup/goldmark/render_hooks.go | 4 | ||||
-rw-r--r-- | markup/highlight/highlight.go | 3 |
5 files changed, 15 insertions, 4 deletions
diff --git a/markup/converter/converter.go b/markup/converter/converter.go index e5a07f1a1..544d4841a 100644 --- a/markup/converter/converter.go +++ b/markup/converter/converter.go @@ -15,6 +15,7 @@ package converter import ( "bytes" + "context" "github.com/gohugoio/hugo/common/hexec" "github.com/gohugoio/hugo/common/loggers" @@ -141,6 +142,9 @@ type DocumentContext struct { // RenderContext holds contextual information about the content to render. type RenderContext struct { + // Ctx is the context.Context for the current Page render. + Ctx context.Context + // Src is the content to render. Src []byte diff --git a/markup/converter/hooks/hooks.go b/markup/converter/hooks/hooks.go index 7eede0710..55d7c1127 100644 --- a/markup/converter/hooks/hooks.go +++ b/markup/converter/hooks/hooks.go @@ -14,6 +14,7 @@ package hooks import ( + "context" "io" "github.com/gohugoio/hugo/common/hugio" @@ -85,12 +86,12 @@ type AttributesOptionsSliceProvider interface { } type LinkRenderer interface { - RenderLink(w io.Writer, ctx LinkContext) error + RenderLink(cctx context.Context, w io.Writer, ctx LinkContext) error identity.Provider } type CodeBlockRenderer interface { - RenderCodeblock(w hugio.FlexiWriter, ctx CodeblockContext) error + RenderCodeblock(cctx context.Context, w hugio.FlexiWriter, ctx CodeblockContext) error identity.Provider } @@ -119,7 +120,7 @@ type HeadingContext interface { // HeadingRenderer describes a uniquely identifiable rendering hook. type HeadingRenderer interface { // Render writes the rendered content to w using the data in w. - RenderHeading(w io.Writer, ctx HeadingContext) error + RenderHeading(cctx context.Context, w io.Writer, ctx HeadingContext) error identity.Provider } diff --git a/markup/goldmark/codeblocks/render.go b/markup/goldmark/codeblocks/render.go index 739781de1..cf5a0f296 100644 --- a/markup/goldmark/codeblocks/render.go +++ b/markup/goldmark/codeblocks/render.go @@ -124,6 +124,7 @@ func (r *htmlRenderer) renderCodeBlock(w util.BufWriter, src []byte, node ast.No cr := renderer.(hooks.CodeBlockRenderer) err := cr.RenderCodeblock( + ctx.RenderContext().Ctx, w, cbctx, ) diff --git a/markup/goldmark/render_hooks.go b/markup/goldmark/render_hooks.go index f36f9f4e6..0bd800dc0 100644 --- a/markup/goldmark/render_hooks.go +++ b/markup/goldmark/render_hooks.go @@ -181,6 +181,7 @@ func (r *hookedRenderer) renderImage(w util.BufWriter, source []byte, node ast.N attrs := r.filterInternalAttributes(n.Attributes()) err := lr.RenderLink( + ctx.RenderContext().Ctx, w, imageLinkContext{ linkContext: linkContext{ @@ -271,6 +272,7 @@ func (r *hookedRenderer) renderLink(w util.BufWriter, source []byte, node ast.No ctx.Buffer.Truncate(pos) err := lr.RenderLink( + ctx.RenderContext().Ctx, w, linkContext{ page: ctx.DocumentContext().Document, @@ -340,6 +342,7 @@ func (r *hookedRenderer) renderAutoLink(w util.BufWriter, source []byte, node as } err := lr.RenderLink( + ctx.RenderContext().Ctx, w, linkContext{ page: ctx.DocumentContext().Document, @@ -428,6 +431,7 @@ func (r *hookedRenderer) renderHeading(w util.BufWriter, source []byte, node ast anchor := anchori.([]byte) err := hr.RenderHeading( + ctx.RenderContext().Ctx, w, headingContext{ page: ctx.DocumentContext().Document, diff --git a/markup/highlight/highlight.go b/markup/highlight/highlight.go index b74997700..410beb740 100644 --- a/markup/highlight/highlight.go +++ b/markup/highlight/highlight.go @@ -14,6 +14,7 @@ package highlight import ( + "context" "fmt" gohtml "html" "html/template" @@ -122,7 +123,7 @@ func (h chromaHighlighter) HighlightCodeBlock(ctx hooks.CodeblockContext, opts a }, nil } -func (h chromaHighlighter) RenderCodeblock(w hugio.FlexiWriter, ctx hooks.CodeblockContext) error { +func (h chromaHighlighter) RenderCodeblock(cctx context.Context, w hugio.FlexiWriter, ctx hooks.CodeblockContext) error { cfg := h.cfg attributes := ctx.(hooks.AttributesOptionsSliceProvider).AttributesSlice() |