Help us shape the future of Go! Take the 2026 Go Developer Survey

termmd

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package termmd renders Markdown for a terminal as it streams in.

A Renderer buffers text until a block is complete (a paragraph ends at a blank line, a fence at its closing line, a list item at the next item) and then writes that block once, wrapped to the width, so streamed text never re-renders. Flush writes whatever is still buffered, so a stream that ends mid-block loses nothing. With Color off the output has no escape codes but keeps the structure: indentation, bullets, code-block borders and table columns.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

func Render(md string, opt Options) string

Render renders a whole document.

func RuneWidth

func RuneWidth(r rune) int

RuneWidth is the number of terminal columns r takes: 0 for controls and combining marks, 2 for East Asian wide and fullwidth characters and most emoji, 1 otherwise. It is a small table, not a full UAX #11 implementation, but covers CJK, Hangul, kana, fullwidth forms and emoji.

func StringWidth

func StringWidth(s string) int

StringWidth is the number of terminal columns s takes. s must not hold escape sequences.

func SupportsHyperlinks(getenv func(string) string) bool

SupportsHyperlinks reports whether the terminal described by getenv clearly renders OSC 8 hyperlinks. Unknown terminals, tmux and screen get false: there the escape can show up as garbage.

Types

type Options

type Options struct {
	Width      int  // columns to wrap to; under 20 means 80
	Color      bool // ANSI styles and Unicode borders and bullets
	Hyperlinks bool // OSC 8 links (only with Color)
}

Options configure a Renderer.

type Renderer

type Renderer struct {
	// contains filtered or unexported fields
}

Renderer turns streamed Markdown into terminal text. It is not safe for concurrent use.

func New

func New(w io.Writer, opt Options) *Renderer

New returns a Renderer writing to w.

func (*Renderer) Flush

func (r *Renderer) Flush()

Flush writes everything still buffered, ending any open block. An unclosed fence is written as a code block.

func (*Renderer) Write

func (r *Renderer) Write(s string)

Write adds streamed text. Complete blocks are written; the rest waits.

Jump to

Keyboard shortcuts

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