Documentation
¶
Overview ¶
Package tviewmd renders markdown to tview color-tagged text.
It parses CommonMark + GFM markdown (via goldmark) into a renderer-neutral block/segment model, then emits tview color tags directly — suitable for a tview.TextView with SetWrap(true). No ANSI round-trip is required.
The primary entry points are Render (parse + render) and RenderTView (render pre-parsed blocks). Callers that want to inspect or transform the document can use Parse to obtain the intermediate []Block representation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Render ¶
Render parses src and renders it to tview color-tagged text. It is the convenience entry point for callers that do not need the intermediate []Block.
func RenderTView ¶
RenderTView renders parsed blocks to tview color-tagged text suitable for a tview.TextView configured with SetWrap(true). The output contains tview color tags ([fg:bg:flags] ... [-:-:-]); the TextView performs word-wrapping.
Types ¶
type Block ¶
type Block struct {
Kind BlockKind
Level int // heading level 1-6 (BlockHeading only)
Segments []Segment // paragraph, heading, blockquote inline content
Code CodeBlock // BlockCodeBlock only
Items []ListItem // BlockList only
Table TableData // BlockTable only
}
Block is one block-level element. The field matching Kind is populated; the others are zero-valued.
type BlockKind ¶
type BlockKind int
BlockKind enumerates block-level markdown elements.
const ( // BlockParagraph is a run of inline content (text + emphasis + code + links). BlockParagraph BlockKind = iota // BlockHeading is a level 1-6 heading. Level holds the depth. BlockHeading // BlockCodeBlock is a fenced or indented code block. Code holds language+source. BlockCodeBlock // BlockList is an ordered or unordered list. Items holds the entries. BlockList // BlockBlockquote is a quoted block. Segments holds the flattened inline content. BlockBlockquote // BlockTable is a GFM table. Table holds header, rows, and column alignments. BlockTable // BlockThematicBreak is a horizontal rule. BlockThematicBreak )
type CodeBlock ¶
type CodeBlock struct {
Lang string // language hint from the info string (may be empty)
Source string
}
CodeBlock holds a fenced or indented code block.
type ListItem ¶
type ListItem struct {
Segments []Segment
Children []ListItem // nested list items
Ordered bool
// Index is the 1-based ordinal for ordered items.
Index int
}
ListItem is one entry in a List block.
type Options ¶
type Options struct {
// Width is used for horizontal-rule length and table column sizing. 0 = 80.
Width int
// NoHighlight disables chroma syntax highlighting for fenced code blocks.
NoHighlight bool
// Theme is the color theme. The zero value uses DefaultTheme().
Theme Theme
}
Options configure rendering. The zero value renders with the default theme, syntax highlighting enabled, and an 80-column width for rules and tables.
type Segment ¶
type Segment struct {
Text string
Style Style
// Link, when non-empty, marks Text as the link label and Link as the URL.
Link string
// Code marks the segment as inline code. Renderers may use a distinct
// background/foreground for code spans.
Code bool
}
Segment is a single styled inline run of text. Exactly one rendering hint applies: Code, Link, or a plain Style.
type Style ¶
type Style struct {
FG string
BG string
Bold bool
Italic bool
Underline bool
Strikethrough bool
Dim bool
}
Style is renderer-neutral inline formatting. Empty color fields mean "inherit the surrounding style"; the renderer maps the flags to its native emphasis syntax.
type TableData ¶
type TableData struct {
Header []TableCell
Rows [][]TableCell
// Aligns is the per-column alignment declared in the delimiter row.
Aligns []TextAlign
}
TableData holds a parsed GFM table.
type Theme ¶
type Theme struct {
// Heading colors per level (index 0 = H1). Used by the tview backend.
Heading [6]string
Link string
InlineCodeFG string
InlineCodeBG string
CodeBlockFG string
QuoteFG string
Hr string
}
Theme holds the color scheme used by renderers. Colors are expressed in any form the target backend understands (tview accepts named colors like "red", hex like "#ff8c42", and "default").
func DefaultTheme ¶
func DefaultTheme() Theme
DefaultTheme returns a dark-terminal-friendly theme tuned for readability on a black/default background.