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 ¶
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 ¶
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
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 ¶
NewRenderer creates a new markdown renderer instance.
func (*Renderer) RenderContent ¶
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.