Documentation
¶
Overview ¶
Package markdown renders a lenient, streaming-stable subset of Markdown to styled terminal lines using Harbor's semantic theme tokens.
The renderer is deliberately dependency-free and deferred: an inline span is only styled once its closing delimiter is present in the source, so rendering a progressively growing document never retro-changes an already-completed block. That keeps streamed assistant output flicker-free — the rendered prefix of a document is stable as more text arrives.
Two output shapes are offered over one shared layout pass, so they cannot drift:
- RenderSpans returns plain text plus the style it renders under, for a cell-grid canvas that applies styling itself. This is the preferred API.
- Render returns pre-styled, right-filled strings for callers that write escape sequences straight to a terminal.
Both wrap on grapheme boundaries and route every width calculation through the ui package, so east-asian text and emoji stay within budget.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Render ¶
Render renders markdown source to a slice of already-styled terminal lines, each fitting within width visible cells. baseRole is the default text role (RoleText for answers, RoleMuted for reasoning). indent is a left pad in cells applied to every line, continuation lines included.
Unlike RenderSpans, every returned line is right-filled to exactly width visible cells and carries ANSI escapes. Callers writing into a cell-grid canvas want RenderSpans instead: styled strings cannot be re-split into grapheme clusters safely.
The parse is lenient: an unmatched inline delimiter or an unclosed fenced code block renders as literal text until its closer arrives, guaranteeing that earlier completed blocks never change as src grows.
func RenderSpans ¶
RenderSpans renders markdown to wrapped lines of styled spans. Line i is composed by drawing each span left-to-right, advancing x by Span.Width. Spans include the leading indent as a plain span of spaces, so every line can be placed at the same x origin. baseRole is the default text role (RoleText for answers, RoleMuted for reasoning).
Span text is always plain, so it is safe to hand to a cell-grid canvas that re-splits text on grapheme clusters. The summed Span.Width of a line never exceeds width, and lines are not right-filled with trailing padding — a blank block separator is returned as a line with no spans. Code blocks and rules do paint their full content width, because their background is part of the design rather than incidental padding.
Types ¶
type Span ¶
type Span struct {
// Text is plain text and never contains escape sequences.
Text string
// Style is the span's style, resolved from the theme.
Style lipgloss.Style
// Width is the span's visible cell count, equal to ui.Width(Text).
Width int
}
Span is a styled run of plain text within a rendered line.