Documentation
¶
Overview ¶
Package markdown provides markdown parsing and rendering for terminal UIs. It uses goldmark for parsing and custom rendering to the compositor system.
Index ¶
- Variables
- func MergeStyle(base, inline compositor.Style) compositor.Style
- func Walk(node ast.Node, fn WalkFunc) error
- type BoxDrawings
- type EnhancedTable
- type EnhancedTableRenderer
- type Highlighter
- type Parser
- type Renderer
- func (r *Renderer) CodeBlockBackground() compositor.Style
- func (r *Renderer) Render(source, content string) []StyledLine
- func (r *Renderer) RenderAST(source string, root ast.Node, content string) []StyledLine
- func (r *Renderer) RenderASTWidth(source string, root ast.Node, content string, maxWidth int) []StyledLine
- func (r *Renderer) RenderWidth(source, content string, maxWidth int) []StyledLine
- type StyleConfig
- type StyledLine
- type StyledSpan
- type TableAlignment
- type TableCell
- type TableRendererConfig
- type TableRow
- type WalkFunc
Constants ¶
This section is empty.
Variables ¶
var DoubleBoxDrawings = BoxDrawings{
Horizontal: "═",
Vertical: "║",
TopLeft: "╔",
TopRight: "╗",
BottomLeft: "╚",
BottomRight: "╝",
LeftT: "╠",
RightT: "╣",
TopT: "╦",
BottomT: "╩",
Cross: "╬",
}
DoubleBoxDrawings uses double lines
var HeavyBoxDrawings = BoxDrawings{
Horizontal: "━",
Vertical: "┃",
TopLeft: "┏",
TopRight: "┓",
BottomLeft: "┗",
BottomRight: "┛",
LeftT: "┣",
RightT: "┫",
TopT: "┳",
BottomT: "┻",
Cross: "╋",
}
HeavyBoxDrawings uses heavy lines for emphasis
var RoundedBoxDrawings = BoxDrawings{
Horizontal: "─",
Vertical: "│",
TopLeft: "╭",
TopRight: "╮",
BottomLeft: "╰",
BottomRight: "╯",
LeftT: "├",
RightT: "┤",
TopT: "┬",
BottomT: "┴",
Cross: "┼",
}
RoundedBoxDrawings uses rounded corners for a softer look
var SharpBoxDrawings = BoxDrawings{
Horizontal: "─",
Vertical: "│",
TopLeft: "┌",
TopRight: "┐",
BottomLeft: "└",
BottomRight: "┘",
LeftT: "├",
RightT: "┤",
TopT: "┬",
BottomT: "┴",
Cross: "┼",
}
SharpBoxDrawings uses sharp corners for a technical look
Functions ¶
func MergeStyle ¶
func MergeStyle(base, inline compositor.Style) compositor.Style
MergeStyle combines a base style with inline style attributes.
Types ¶
type BoxDrawings ¶
type BoxDrawings struct {
Horizontal string
Vertical string
TopLeft string
TopRight string
BottomLeft string
BottomRight string
LeftT string
RightT string
TopT string
BottomT string
Cross string
}
Box drawing characters for table borders
type EnhancedTable ¶
type EnhancedTable struct {
Rows []TableRow
Columns int
ColWidths []int
ColAligns []TableAlignment
TotalWidth int
}
EnhancedTable represents a parsed markdown table with layout info
func ParseTable ¶
func ParseTable(table *extast.Table, source []byte) *EnhancedTable
ParseTable parses a goldmark AST table into an EnhancedTable
func (*EnhancedTable) CalculateWidths ¶
func (t *EnhancedTable) CalculateWidths(config TableRendererConfig, maxWidth int)
CalculateWidths computes optimal column widths
func (*EnhancedTable) Render ¶
func (t *EnhancedTable) Render(config TableRendererConfig) []StyledLine
Render renders the table to styled lines
type EnhancedTableRenderer ¶
type EnhancedTableRenderer struct {
// contains filtered or unexported fields
}
EnhancedTableRenderer handles rich table rendering
func NewEnhancedTableRenderer ¶
func NewEnhancedTableRenderer(config TableRendererConfig) *EnhancedTableRenderer
NewEnhancedTableRenderer creates a new table renderer
func (*EnhancedTableRenderer) RenderTable ¶
func (r *EnhancedTableRenderer) RenderTable(table *extast.Table, source []byte, maxWidth int) []StyledLine
RenderTable renders a markdown table with enhanced formatting
type Highlighter ¶
type Highlighter struct {
// contains filtered or unexported fields
}
Highlighter applies syntax highlighting to fenced code blocks.
func NewHighlighter ¶
func NewHighlighter(t *theme.Theme) *Highlighter
NewHighlighter returns a theme-aware highlighter.
func (*Highlighter) Highlight ¶
func (h *Highlighter) Highlight(code, language string, cfg *StyleConfig) []StyledLine
Highlight tokenizes and styles code into markdown lines.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser wraps goldmark for markdown parsing.
func NewParser ¶
func NewParser() *Parser
NewParser creates a new markdown parser with common extensions enabled.
type Renderer ¶
type Renderer struct {
// contains filtered or unexported fields
}
Renderer turns markdown into styled lines for the TUI.
func NewRenderer ¶
NewRenderer creates a renderer using the provided theme.
func (*Renderer) CodeBlockBackground ¶
func (r *Renderer) CodeBlockBackground() compositor.Style
CodeBlockBackground returns the default code block background style.
func (*Renderer) Render ¶
func (r *Renderer) Render(source, content string) []StyledLine
Render parses markdown and returns styled lines for the given source.
func (*Renderer) RenderASTWidth ¶
func (r *Renderer) RenderASTWidth(source string, root ast.Node, content string, maxWidth int) []StyledLine
RenderASTWidth renders a pre-parsed AST with width-sensitive blocks constrained to maxWidth.
func (*Renderer) RenderWidth ¶
func (r *Renderer) RenderWidth(source, content string, maxWidth int) []StyledLine
RenderWidth parses markdown and constrains width-sensitive blocks such as tables to maxWidth. A non-positive width keeps their natural size.
type StyleConfig ¶
type StyleConfig struct {
// Headers
H1 compositor.Style
H2 compositor.Style
H3 compositor.Style
H4 compositor.Style
H5 compositor.Style
H6 compositor.Style
// Inline styles
Bold compositor.Style
Italic compositor.Style
BoldItalic compositor.Style
Code compositor.Style
Strikethrough compositor.Style
Link compositor.Style
LinkURL compositor.Style
// Block elements
Blockquote compositor.Style
BlockquoteBorder compositor.Style
ListBullet compositor.Style
ListNumber compositor.Style
HorizontalRule compositor.Style
// Code blocks
CodeBlockBorder compositor.Style
CodeBlockBG compositor.Style
CodeBlockLang compositor.Style
CodeBlockLineNumber compositor.Style
// Tables
TableHeader compositor.Style
TableCell compositor.Style
TableBorder compositor.Style
// Base text
Text compositor.Style
}
StyleConfig maps markdown elements to compositor styles.
func DefaultStyleConfig ¶
func DefaultStyleConfig(t *theme.Theme) *StyleConfig
DefaultStyleConfig returns style configuration based on the theme.
func (*StyleConfig) WithBaseText ¶
func (c *StyleConfig) WithBaseText(base compositor.Style) *StyleConfig
WithBaseText returns a copy of the config with base text styles overridden.
type StyledLine ¶
type StyledLine struct {
Spans []StyledSpan
Prefix []StyledSpan // Repeated prefix for wrapped lines (e.g., list bullets)
Indent int // Indentation level for nested structures
IsCode bool // Inside a code block
IsCodeHeader bool // Header line for a code block
Anchor string // Anchor id for headings
HeadingLevel int // Heading level (1-6)
Language string // Language for syntax highlighting
CodeLineNumberWidth int // Width of the code line number gutter
CodeLineNumberOptional bool // Line numbers appear on hover for short blocks
BlankLine bool // Empty line for spacing
}
StyledLine represents a line composed of styled spans.
func Plain ¶
func Plain(text string, style compositor.Style) StyledLine
Plain creates a StyledLine from plain text with default style.
type StyledSpan ¶
type StyledSpan struct {
Text string
Style compositor.Style
}
StyledSpan represents a span of text with consistent styling.
type TableAlignment ¶
type TableAlignment int
TableAlignment represents cell alignment
const ( AlignLeft TableAlignment = iota AlignCenter AlignRight )
type TableCell ¶
type TableCell struct {
Text string
Alignment TableAlignment
IsHeader bool
Width int // Computed width
}
TableCell represents a single cell in a table
type TableRendererConfig ¶
type TableRendererConfig struct {
BoxDrawings BoxDrawings
HeaderStyle compositor.Style
CellStyle compositor.Style
BorderStyle compositor.Style
Padding int
MinColumnWidth int
}
TableRendererConfig configures the table rendering
func DefaultTableRendererConfig ¶
func DefaultTableRendererConfig(t *theme.Theme) TableRendererConfig
DefaultTableRendererConfig returns a default configuration
func TableStyleCompact ¶
func TableStyleCompact(t *theme.Theme) TableRendererConfig
Alternative styles for different contexts
func TableStyleHeavy ¶
func TableStyleHeavy(t *theme.Theme) TableRendererConfig
func TableStyleMinimal ¶
func TableStyleMinimal(t *theme.Theme) TableRendererConfig