Documentation
¶
Overview ¶
Package diagrams provides server-side renderers for diagram-as-code blocks (currently mermaid via Kroki) so tinkerdown sites can ship pre-rendered SVGs and skip the heavyweight client-side runtime.
The package exposes a small Renderer interface; the concrete Kroki implementation talks to https://kroki.io by default but accepts any Kroki-compatible URL (self-hosted instances are encouraged for production use). Results are content-hash-cached in memory so each unique source string costs at most one HTTP round-trip per process lifetime.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type KrokiRenderer ¶
type KrokiRenderer struct {
BaseURL string // e.g. "https://kroki.io"
DiagramKey string // Kroki diagram type, e.g. "mermaid"
Timeout time.Duration // per-request timeout (default 5s)
HTTPClient *http.Client // injectable for tests; nil → built from Timeout
// contains filtered or unexported fields
}
KrokiRenderer talks to a Kroki HTTP service. The default base URL targets the public instance at https://kroki.io which is rate-limited but adequate for low-traffic sites whose unique-diagram count is small (because cache hits skip the network entirely). For higher traffic, point BaseURL at a self-hosted Kroki container.
func NewKrokiMermaid ¶
func NewKrokiMermaid(baseURL string) *KrokiRenderer
NewKrokiMermaid returns a KrokiRenderer pre-configured for mermaid. baseURL may be empty to use the public https://kroki.io instance.
func (*KrokiRenderer) Render ¶
func (k *KrokiRenderer) Render(source []byte) ([]byte, error)
Render returns the SVG bytes for the given mermaid source. Cache hits (sha256-keyed) skip the network. On any HTTP error or non-2xx response the source is NOT cached — transient failures get retried on the next call.