markdown

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 15 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

Overview

Package markdown wraps Glamour for cached markdown-to-ANSI rendering with width-based revalidation, falling back to plain text wrapping for narrow terminals.

RenderContent returns styled lines for existing document/issue/preview consumers. RenderMapped is an adjacent result: the same lines plus source anchors derived from goldmark block positions and wrap math, so a click or scroll offset can be mapped back to a source line without parsing ANSI.

Index

Constants

View Source
const (
	// MinWidthForMarkdown is the minimum terminal width for markdown rendering.
	// Below this, falls back to plain text wrapping.
	MinWidthForMarkdown = 30

	// MaxCacheEntries is the maximum number of cached renders before eviction.
	MaxCacheEntries = 100
)

Variables

This section is empty.

Functions

func WrapText

func WrapText(text string, maxWidth int) []string

WrapText wraps text to fit within maxWidth. Used as fallback when terminal is too narrow for markdown rendering.

Types

type Anchor added in v1.0.3

type Anchor struct {
	SourceLine int  // 0-based source line
	SourceCol  int  // 0-based rune offset on that line
	BlockStart int  // 0-based first source line of the containing block
	Precise    bool // line-accurate when true
}

Anchor maps one rendered visual row back to a source location. Precise is true when SourceLine is line-accurate (ordinary paragraphs and headings via wrap math). Tables, fences, and other heavily reshaped constructs degrade to the top of their block with Precise=false.

type MappedRender added in v1.0.3

type MappedRender struct {
	Lines   []string
	Anchors []Anchor
}

MappedRender is a rendered markdown document plus a parallel source map. Lines[i] is what the user sees; Anchors[i] says which source line produced it.

func MapWrappedSource added in v1.0.3

func MapWrappedSource(content string, width int) MappedRender

MapWrappedSource wraps each source line at width and maps every visual row back to that source line plus the starting column of the wrap segment. This is the raw-view / narrow-fallback visual-row policy: always wrap, never truncate.

func (MappedRender) At added in v1.0.3

func (m MappedRender) At(visualRow int) Anchor

At returns the source anchor for a visual row. Out-of-range rows clamp to the nearest mapped line.

func (MappedRender) Click added in v1.0.3

func (m MappedRender) Click(scrollOff, viewRow int) Anchor

Click maps a viewport-relative row plus the view's scroll offset to source.

func (MappedRender) VisualRowForSource added in v1.0.3

func (m MappedRender) VisualRowForSource(sourceLine, sourceCol int) int

VisualRowForSource returns the first visual row whose source position is at or before (sourceLine, sourceCol). Used when leaving edit so the rendered view can recover the line that was being edited.

type Renderer

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

Renderer wraps Glamour for markdown rendering with caching.

func NewRenderer

func NewRenderer() (*Renderer, error)

NewRenderer creates a new markdown renderer instance.

func (*Renderer) RenderContent

func (r *Renderer) RenderContent(content string, width int) []string

RenderContent renders markdown content to styled lines.

func (*Renderer) RenderMapped added in v1.0.3

func (r *Renderer) RenderMapped(content string, width int) MappedRender

RenderMapped renders markdown and a source map for the same width. Existing RenderContent consumers are unchanged; this is an adjacent result.

Jump to

Keyboard shortcuts

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