Documentation
¶
Overview ¶
Package mdrender renders markdown to terminal-styled output using the shared entire CLI base16 palette (magenta H1, cyan H2, blue H3, plus chroma syntax highlighting). Used by `entire dispatch`, `entire review`, and any other command that prints LLM-generated markdown to the terminal.
Two entry points:
- Render: pure function — caller supplies width and background hint.
- RenderForWriter: TTY-aware — renders to a terminal writer with auto-detected width; passes raw markdown through when w is not a terminal (so redirected output is grep-friendly, not full of ANSI). RenderForWriterWithBackground is the same with a caller-supplied background, for commands whose TUI owns the terminal.
Index ¶
- Constants
- func DarkBackgroundFromEnv() bool
- func Render(markdown string, width int, darkBackground bool) (rendered string, err error)
- func RenderForWriter(w io.Writer, markdown string) (string, error)
- func RenderForWriterWithBackground(w io.Writer, markdown string, darkBackground func() bool) (string, error)
Constants ¶
const DefaultTerminalWidth = 80
DefaultTerminalWidth caps glamour word-wrap when no real terminal width is available. Matches the cap used by status_style.getTerminalWidth.
const MaxRenderBytes = 256 * 1024
MaxRenderBytes caps glamour input: its render cost is super-linear (~6s at 2MB, minutes beyond), so above this we return raw markdown unchanged.
Variables ¶
This section is empty.
Functions ¶
func DarkBackgroundFromEnv ¶ added in v0.13.5
func DarkBackgroundFromEnv() bool
DarkBackgroundFromEnv is termenv's background fallback without the terminal query: COLORFGBG's background slot when set, otherwise dark.
func Render ¶
Render produces a glamour-styled string from markdown using the entire CLI palette. width is the word-wrap target; darkBackground selects the dark or light palette variant.
Errors only on glamour renderer construction or render failure — both of which indicate a malformed StyleConfig (programmer error) rather than a runtime condition. Renderer panics are recovered and returned as errors so callers can fall back to raw markdown instead of crashing.
func RenderForWriter ¶
RenderForWriter renders markdown when w is a terminal writer, and returns the input unchanged otherwise. NO_COLOR=1 also disables rendering so pipelines that grep through redirected output work without unwrapping ANSI escape sequences.
Width is auto-detected from w (capped at 80); background palette is detected via termenv.HasDarkBackground.
func RenderForWriterWithBackground ¶ added in v0.13.5
func RenderForWriterWithBackground(w io.Writer, markdown string, darkBackground func() bool) (string, error)
RenderForWriterWithBackground is RenderForWriter with the caller answering the background question; darkBackground runs only when w gets styled output. A command whose TUI owns the terminal passes the TUI's answer: termenv's probe reads the terminal's reply from the tty, racing the TUI's own input reader.
Types ¶
This section is empty.