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 ¶
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 ¶
Hyperlink wraps text in an OSC 8 terminal hyperlink sequence, returning it unchanged when there is no URL to link to. The destination's non-ASCII is percent-encoded, for the reason percentEncodeNonASCII gives.
func LinkifyURLs ¶
LinkifyURLs wraps bare URLs in OSC 8 hyperlink sequences, leaving URLs that already sit inside one alone. A URL ends where a bare link in prose would — at the end of its run of text (linkTokenEnd: a space, a control, punctuation outside ASCII, a wide bracket it did not open), then at what a link's end sheds — and the search for the next one carries on from there, so https://…/one。https://…/two is two links. The run's end is found once and kept for the URLs after the first in it.
func Render ¶
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
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.