markdown

package
v0.78.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2026 License: MIT Imports: 16 Imported by: 3 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func DiffFence(language, diff string) string

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

func Fence(info, code string) string

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

func LanguageOf(path string) string

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

func NestHeadings(source string, depth int) string

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.

func (*Renderer) Lines

func (r *Renderer) Lines(source string, width int) []gotermboard.Line

Lines is source laid out to width. A caller treats them as read-only, since they are kept.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL