markdown

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

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 renders Markdown for the terminal. It wraps glamour for the styling and adds OSC 8 hyperlinks so URLs stay clickable.

Index

Constants

View Source
const DefaultWidth = 80

DefaultWidth is the word wrap used when the caller has no width of its own.

Variables

This section is empty.

Functions

func Hyperlink(text, url string) string

Hyperlink wraps text in an OSC 8 terminal hyperlink sequence, returning it unchanged when there is no URL to link to.

func LinkifyURLs

func LinkifyURLs(text string) string

LinkifyURLs wraps bare URLs in OSC 8 hyperlink sequences, leaving URLs that already sit inside one alone.

func Render

func Render(md htmlutil.Markdown, width int) string

Render renders Markdown as styled terminal output wrapped to width. It falls back to the Markdown source when glamour cannot be set up, so a rendering problem costs formatting rather than the message itself.

Only htmlutil.ToMarkdown can produce the Markdown this accepts: the type is the provenance, so a string from anywhere else cannot reach glamour. The Markdown is still treated as untrusted on the way in and the output is checked on the way out: see prepareSource and contain. One consequence worth knowing is that `&` is always literal here — an entity reference in the source is shown as the characters it was written with, because the HTML it came from already decoded the entities that were meant to be decoded.

Types

type LinkOccurrence added in v1.7.0

type LinkOccurrence struct {
	Destination string
	StartLine   int
	EndLine     int
}

LinkOccurrence describes one selectable hyperlink in rendered document order. Lines are zero-based and inclusive. A wrapped link therefore has different StartLine and EndLine values.

type LinkedRender added in v1.7.0

type LinkedRender struct {
	Text  string
	Links []LinkOccurrence
}

LinkedRender is the contained terminal rendering of one Markdown body and the safe hyperlink occurrences it contains.

func RenderLinked added in v1.7.0

func RenderLinked(md htmlutil.Markdown, width, selected int) LinkedRender

RenderLinked renders one sealed Markdown body and records each selectable hyperlink in the order it appears. selected is a zero-based occurrence index; a negative value leaves all links unselected.

Jump to

Keyboard shortcuts

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