Documentation
¶
Overview ¶
Package renderer renders the given AST to certain formats.
Index ¶
- type Config
- type Context
- type ContextKey
- type ContextOption
- type EmptyHook
- type Extension
- type Helper
- type Hook
- type NodeRenderer
- type Option
- func NewOptionFunc[C any](f func(*C)) Option[C]
- func WithExtensions[W any, C any](ext ...Extension[C]) Option[C]
- func WithHooks[W any, C any](hooks ...Hook[W]) Option[C]
- func WithNodeRenderer[W any, C any](kind ast.NodeKind, nodeRenderer NodeRenderer[W]) Option[C]
- func WithNodeRenderers[W any, C any](nodeRenderers map[ast.NodeKind]NodeRenderer[W]) Option[C]
- type Renderer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context interface {
// Get returns a value associated with the given key.
Get(ContextKey) any
// ComputeIfAbsent computes a value if a value associated with the given key is absent and returns the value.
ComputeIfAbsent(ContextKey, func() any) any
// Set sets the given value to the context.
Set(ContextKey, any)
// Render renders the given node using the renderer associated with this context.
// If no rendering function has been set, it is a no-op and returns nil.
Render(w any, source []byte, n ast.Node) error
}
A Context interface holds information that is necessary to render Markdown text.
func NewContext ¶
func NewContext(opts ...ContextOption) Context
NewContext returns a new rendering Context.
type ContextKey ¶
type ContextKey int
ContextKey is a key that is used to set arbitrary values to the rendering context.
var ContextKeyMax ContextKey
ContextKeyMax is a maximum value of the ContextKey.
type ContextOption ¶
type ContextOption func(*renderContext)
ContextOption is a functional option for NewContext.
func WithRenderFunc ¶
WithRenderFunc sets the rendering function used by Context.Render.
type EmptyHook ¶
type EmptyHook[W any] struct{}
EmptyHook is a Hook that does nothing.
func (*EmptyHook[W]) PostRender ¶
PostRender implements Hook.PostRender.
type Extension ¶
type Extension[C any] interface { // RendererOptions returns the options for the Renderer. RendererOptions(*C) []Option[C] }
Extension is an interface that represents an extension for Renderer.
type Helper ¶
Helper is a helper struct for implementing Renderer.
func (*Helper[W, C]) Config ¶
func (r *Helper[W, C]) Config() *C
Config returns the configuration of this Helper.
func (*Helper[W, C]) Register ¶
func (r *Helper[W, C]) Register(kind ast.NodeKind, n NodeRenderer[W])
Register registers the given NodeRenderer for the given node kind.
type Hook ¶
type Hook[W any] interface { PreRender(w W, source []byte, n ast.Node, rc Context) error PostRender(w W, source []byte, n ast.Node, rc Context) error }
A Hook interface is used for hooking into the rendering process.
type NodeRenderer ¶
type NodeRenderer[W any] interface { Render(w W, source []byte, n ast.Node, entering bool, rc Context) (ast.WalkStatus, error) }
A NodeRenderer interface is used for rendering a given node.
func NodeRendererFunc ¶
func NodeRendererFunc[W any](f func(w W, source []byte, n ast.Node, entering bool, rc Context) (ast.WalkStatus, error)) NodeRenderer[W]
NodeRendererFunc is a function that implements NodeRenderer interface.
type Option ¶
type Option[C any] interface { SetFormatOption(*C) }
Option is a functional option for NewRenderer.
func NewOptionFunc ¶
NewOptionFunc returns a new Option that applies the given function to the configuration.
func WithExtensions ¶
WithExtensions sets the extensions for the Renderer.
func WithNodeRenderer ¶
WithNodeRenderer sets a node renderer for the given node kind.
func WithNodeRenderers ¶
WithNodeRenderers sets the node renderers for the Renderer.