renderer

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package renderer converts markdown to HTML with caching and syntax highlighting.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Document

type Document struct {
	HTML     string
	Metadata Metadata
	Modified time.Time
	Raw      string
}

Document represents a rendered markdown file.

type Metadata

type Metadata struct {
	Raw         map[string]any
	Title       string
	Description string
	Tags        []string
}

Metadata captures optional frontmatter data rendered alongside a document.

func (Metadata) IsZero

func (m Metadata) IsZero() bool

IsZero reports whether the metadata carries any meaningful values.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service renders markdown into HTML with caching. It uses Goldmark for markdown parsing with GitHub-flavored markdown extensions, syntax highlighting, and automatic link transformation for wiki-style navigation. Rendered documents are cached by path and modification time for improved performance.

func NewService

func NewService(logger *slog.Logger) *Service

NewService constructs a markdown renderer with GitHub-flavored markdown support. The renderer includes:

  • GitHub-flavored markdown extensions (tables, strikethrough, task lists, autolinks, etc.)
  • Syntax highlighting with the github-dark theme
  • YAML frontmatter parsing for document metadata
  • Automatic link transformation for .md files to /page/ routes
  • Raw HTML rendering enabled (safe for local-only wikis)
  • Soft line breaks (newlines become spaces, matching GitHub's default behavior)
  • Hard line breaks can be created with two trailing spaces or <br> tags

If logger is nil, the default slog logger is used.

func (*Service) Invalidate

func (s *Service) Invalidate(path string)

Invalidate removes the cached entry for the given path. This should be called when a document is updated or deleted to ensure the next Render call processes the latest content.

func (*Service) Render

func (s *Service) Render(_ context.Context, path string, modTime time.Time, content []byte) (Document, error)

Render converts markdown content to HTML, caching results by path and modification time. If a cached entry exists with a matching modification time, it is returned immediately. Otherwise, the markdown is parsed and rendered, then cached for future requests. The path parameter is used for cache key generation and relative link resolution.

Directories

Path Synopsis
Package d2 provides server-side helpers for compiling D2 diagrams into SVG.
Package d2 provides server-side helpers for compiling D2 diagrams into SVG.
Package transform provides custom rendering transformations for markdown elements.
Package transform provides custom rendering transformations for markdown elements.

Jump to

Keyboard shortcuts

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