render

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block added in v0.5.0

type Block struct {
	Start, Stop int
	HTML        []byte
	Editable    bool
}

Block is one top-level chunk of a rendered document: a direct child of ast.Document — a paragraph, a heading, a whole list, a blockquote, a fenced code block (mermaid included), a table or the footnote list. Start and Stop

type IDSpace added in v0.5.0

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

IDSpace assigns anchor ids for a page that may hold several markdown documents at once. It keeps two levels of bookkeeping:

func NewIDSpace added in v0.5.0

func NewIDSpace() *IDSpace

NewIDSpace returns an empty id space shared by all documents of one page.

func (*IDSpace) DocPrefix added in v0.5.0

func (s *IDSpace) DocPrefix(name string) string

DocPrefix turns a markdown file name into a page-unique document prefix: the base name without extension, slugified ("doc" when nothing survives), with a numeric suffix on collision. The prefix is reserved in the global namespace

func (*IDSpace) IDs added in v0.5.0

func (s *IDSpace) IDs(prefix string) parser.IDs

IDs returns the parser.IDs implementation for one document of this space.

func (*IDSpace) Lookup added in v0.5.0

func (s *IDSpace) Lookup(prefix, local string) (string, bool)

Lookup returns the id emitted for a local anchor of the given document, and whether such an anchor exists.

type ImageCache added in v0.5.0

type ImageCache interface {
	Load(abs string) (uri string, ok bool)
	Store(abs, uri string, mod time.Time)
}

ImageCache memoises the data: URIs produced by inlining local images, keyed by absolute file path. Edit mode re-parses every document of the page after each accepted edit, and without a cache each of those passes would re-read and

type MemImageCache added in v0.5.0

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

MemImageCache is an in-memory ImageCache safe for concurrent use.

func NewMemImageCache added in v0.5.0

func NewMemImageCache() *MemImageCache

NewMemImageCache returns an empty cache ready for use.

func (*MemImageCache) Load added in v0.5.0

func (c *MemImageCache) Load(abs string) (string, bool)

Load returns the memoised URI for abs. It misses when nothing was stored for the path, when the file can no longer be stat'ed (deleted or unreadable — the caller's own read then produces the proper warning) or when its mtime differs

func (*MemImageCache) Store added in v0.5.0

func (c *MemImageCache) Store(abs, uri string, mod time.Time)

Store records uri for abs. A zero mod is ignored: the mtime of the file could not be determined, so the entry would never be provably fresh and caching it would only grow the map.

type Options added in v0.5.0

type Options struct {
	Prefix   string
	IDs      *IDSpace
	Siblings map[string]string
	Images   ImageCache
}

Options tunes how a document is rendered as part of a possibly multi-document page. The zero value renders a stand-alone document exactly as a single-file run does.

type Result

type Result struct {
	HTML       []byte
	Blocks     []Block
	Title      string
	TOC        []TOCEntry
	HasMermaid bool
	HasKatex   bool
	Warnings   []string
}

Result is the outcome of rendering a markdown document. HTML is a content fragment (not a full document); the page package wraps it into a standalone HTML file.

func Render

func Render(src []byte, mdPath string, opts Options) (Result, error)

Render converts src into an HTML fragment. mdPath is used to derive the fallback title (its basename) when the document has no H1 and as the base directory (its dir) against which relative image paths are resolved for

type TOCEntry added in v0.2.0

type TOCEntry struct {
	Level int
	ID    string
	Text  string
}

TOCEntry is one table-of-contents item: a heading together with the anchor id generated for it during parsing.

Jump to

Keyboard shortcuts

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