mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-17 21:01:26 +02:00
@@ -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
|
||||
|
||||
|
@@ -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
|
||||
}
|
||||
|
||||
|
@@ -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,
|
||||
)
|
||||
|
@@ -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,
|
||||
|
@@ -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()
|
||||
|
Reference in New Issue
Block a user