render

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: MIT Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CodeBlockRef

type CodeBlockRef struct {
	Lang    string
	Content string
	Start   int // first line of the frame, inclusive
	End     int // last line of the frame, inclusive
}

CodeBlockRef locates a rendered code block in the output.

Line extents are recorded during assembly rather than recovered afterwards. The previous approach matched a block's first source line against the stripped ANSI output, which silently failed whenever highlighting altered the text and gave no way to tell a miss from a block at line zero.

type Document

type Document struct {
	ANSI           string
	SectionOffsets []int
	CodeBlocks     []CodeBlockRef
	Images         []ImageRef
}

Document is a rendered markdown file plus the offsets needed to navigate it.

type ImageRef

type ImageRef struct {
	Alt    string
	Target string // absolute path, or URL for remote images
	Line   int    // first line of the image block
	Rows   int    // lines the block occupies

	// Anchored marks an image drawn at the cursor rather than into text
	// cells. iTerm2 and sixel bitmaps cannot be clipped, so the viewport has
	// to suppress them unless the whole block is on screen.
	Anchored bool
}

ImageRef locates a rendered image and records what it points at, so the TUI can open the underlying file and manage anchored placements.

type Renderer

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

Renderer turns markdown sections into ANSI. It holds the palette and colour profile so they are resolved once rather than per render, and caches the glamour renderer across rebuilds at the same width.

func New

func New(pal theme.Palette) *Renderer

New returns a Renderer for pal, detecting the terminal's colour profile.

func (*Renderer) Build

func (r *Renderer) Build(sections []string, fm *mdutil.FrontMatter, paneWidth int) (*Document, error)

Build renders sections at the given pane width.

Rather than handing whole sections to glamour, each is segmented so that tables, fenced code and alerts can be rendered directly; glamour keeps the prose. Spacing is applied here, one blank line between blocks and between sections, instead of compounding a join with glamour's own block padding.

func (*Renderer) Palette

func (r *Renderer) Palette() theme.Palette

Palette exposes the renderer's palette so the TUI chrome can match it.

func (*Renderer) Protocol

func (r *Renderer) Protocol() termimg.Protocol

Protocol reports the terminal graphics protocol in use, if any.

func (*Renderer) SetBaseDir

func (r *Renderer) SetBaseDir(dir string)

SetBaseDir sets the directory relative image paths are resolved against.

func (*Renderer) SetProtocol

func (r *Renderer) SetProtocol(p termimg.Protocol)

SetProtocol overrides the detected graphics protocol. Tests use it to exercise each encoder without depending on the terminal running them.

Jump to

Keyboard shortcuts

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