markup

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package markup provides Rich-style markup parsing for styled terminal text.

Markup syntax:

  • [bold]text[/bold] or [bold]text[/] - apply bold style
  • [red]text[/] - apply color
  • [bold red on white]text[/] - combine styles
  • [#ff0000]text[/] - hex colors
  • [link=https://example.com]click here[/link] - hyperlinks
  • \\[ - escaped bracket (renders as literal [)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Escape

func Escape(text string) string

Escape escapes a string so it won't be interpreted as markup.

func Render

func Render(markup string) []segment.Segment

Render is a convenience function that parses and renders markup to segments.

func Strip

func Strip(markup string) string

Strip removes all markup tags from a string, returning plain text.

func VisibleLength

func VisibleLength(markup string) int

VisibleLength returns the terminal cell width of the visible text (without markup tags). This accounts for double-width characters (CJK), zero-width characters, etc.

Types

type Span

type Span struct {
	Start int
	End   int
	Style style.Style
}

Span represents a styled region of text.

type Text

type Text struct {
	Plain string // Plain text without markup
	Spans []Span // Styled regions
}

Text represents parsed markup with styled spans.

func Parse

func Parse(markup string) Text

Parse parses a markup string into a Text object.

func (Text) Render

func (t Text) Render() []segment.Segment

Render converts the Text to segments.

Jump to

Keyboard shortcuts

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