Documentation
¶
Overview ¶
Package markdown lays markdown out as a board's lines at a given width, naming a TUI theme role for each cell, such as markdown.heading.2 or syntax.keyword. The board resolves a role in its theme as it draws, so a reload recolors a document already laid out. It wraps before it styles, so each line carries its own colors, and a bullet's wrapped lines hang under its text.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DiffFence ¶ added in v0.77.0
DiffFence is a unified diff as a fenced block whose changed lines are language's code. The renderer colors each line as that language and lays each added or removed line on its role's tint, as delta draws a diff. Every other markdown reader sees a diff fence, because the language is the info's second word. An empty language is a plain diff fence.
func Fence ¶ added in v0.71.0
Fence is code as a fenced block named info, which no line of the code can close. Its fence is a run of backticks longer than any in the code, and three at the least. The code loses its terminal controls before the count, as the renderer strips them before it parses, so no control between two runs of backticks joins them into a closing fence once it is drawn. info names the block's language or kind, then any words after a space, as DiffFence's does, and the caller gives one with no backtick or line break.
func LanguageOf ¶ added in v0.77.0
LanguageOf is the language a fence names for the file at path, from its name, or "" where no lexer knows the name.
func NestHeadings ¶ added in v0.57.0
NestHeadings moves every heading in source deeper by one amount, so its shallowest sits at depth. Text pasted under a section then keeps its own headings inside that section rather than closing it, which is what the Reader's path and its section jumps read. A heading goes no deeper than 6, and source whose shallowest heading is already at depth or deeper stays as it is. A setext heading becomes one ATX line, and a # inside a code block is code.
Types ¶
type Renderer ¶
type Renderer struct {
// WrapEveryFence wraps a text or bare fence's long lines too, for a text whose every word
// has to reach the reader, where a diagram losing its line-up costs less than losing its
// end.
WrapEveryFence bool
// contains filtered or unexported fields
}
Renderer lays out markdown and keeps what it laid out, because a board redraws on every key and tick while its text stays the same. It belongs to one goroutine.
func New ¶
func New(textRun func(text, code string) gotermboard.Line) *Renderer
New is a Renderer. textRun, when not nil, turns a run of prose into cells, so a caller can color what it recognizes there. code is the run's attributes, and a cell handed back in code also wears the run's theme role. A code span or block never reaches it.