src.elv.shsrc.elv.sh/pkg/ui/styledown Index | Files

package styledown

import "src.elv.sh/pkg/ui/styledown"

Styledown is a simple markup language for representing styled text.

In the most basic form, Styledown markup consists of alternating text lines and style lines, where each character in the style line specifies the style of the character directly above it. For example:

foobar
***###
lorem
_____

represents two lines:

  1. "foo" in bold plus "bar" in reverse video
  2. "lorem" in underline

The following style characters are built-in:

This package can be used as a Go library or via Elvish's render-styledown command (https://elv.sh/ref/builtin.html#render-styledown).

Double-width characters

Characters in text and style lines are matched up using their visual width, as calculated by src.elv.sh/pkg/wcwidth.OfRune. This means that double-width characters need to have their style character doubled:

好 foo
** ###

The two style characters must be the same.

Configuration stanza

An optional configuration stanza can follow the text and style lines (the content stanza), separated by a single newline. It can define additional style characters like this:

foobar
rrrGGG

r fg-red
G inverse fg-green

Each line consists of the style character and one or more stylings as recognized by src.elv.sh/pkg/ui.ParseStyling, separated by whitespaces. The character must be a single Unicode codepoint and have a visual width of 1.

The configuration stanza can also contain additional options, and there's currently just one:

Rationale

Styledown is suitable for authoring a large chunk of styled text when the exact width and alignment of text need to be preserved.

For example, it can be used to manually create and edit terminal mockups. In future it will be used in Elvish's tests for its terminal UI.

Index

Functions

func Render

func Render(s string) (ui.Text, error)

Render renders Styledown markup. If the markup has parse errors, the error will start with "line x", where x is a 1-based line number.

Source Files

styledown.go

Version
v0.21.0 (latest)
Published
Aug 13, 2024
Platform
linux/amd64
Imports
5 packages
Last checked
3 days ago

Tools for package owners.