imagerender

package
v1.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForPage

func ForPage(lookup ImageLookupFunc) util.PrioritizedValue

ForPage creates a NodeRendererFunc priority pair for use in goldmark options. Priority 50 overrides the default image renderer (priority 1000).

Types

type Extension

type Extension struct {
	Lookup   ImageLookupFunc // legacy: creates a new Renderer with this lookup
	Renderer *Renderer       // preferred: reuse an existing Renderer (lookup swappable at runtime)
}

Extension registers the custom image renderer with Goldmark.

func (*Extension) Extend

func (e *Extension) Extend(m goldmark.Markdown)

Extend implements goldmark.Extender.

type ImageLookupFunc

type ImageLookupFunc func(imageName string, opts asset.ImageOptions) *asset.ProcessedImage

ImageLookupFunc looks up processed image data for a page's bundle-relative image. opts carries per-image overrides parsed from Goldmark attributes.

type Renderer

type Renderer struct {
	html.Config
	Lookup ImageLookupFunc
	// AssetURL resolves a site-absolute path in the fallback <img>; nil leaves
	// it as written.
	AssetURL    func(string) string
	HasImages   bool // set true when at least one image is rendered
	LazyLoading bool // site config; the first image per page is always eager
	// contains filtered or unexported fields
}

Renderer replaces the default Goldmark image renderer for bundle-relative images. Other images render as a standard <img>: site-absolute paths get the base path through AssetURL, and full URLs pass through. The Lookup field can be swapped at runtime without rebuilding the Goldmark instance.

func NewRenderer

func NewRenderer(lookup ImageLookupFunc) *Renderer

NewRenderer creates a Goldmark image node renderer. If lookup is nil, all images render as standard <img> tags. The Lookup can be changed later via direct field assignment.

func (*Renderer) RegisterFuncs

func (r *Renderer) RegisterFuncs(reg gmrenderer.NodeRendererFuncRegisterer)

RegisterFuncs registers the renderer for ast.KindImage.

func (*Renderer) ResetPage added in v1.2.0

func (r *Renderer) ResetPage()

ResetPage zeroes the per-page image counter before each page render.

func (*Renderer) String

func (r *Renderer) String() string

String implements fmt.Stringer for debugging.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL