styledown

package
v0.21.0-dev.0...-0c50cc8 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: BSD-2-Clause Imports: 5 Imported by: 0

Documentation

Overview

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:

  • space for no style
  • * for bold
  • _ for underline
  • # for reverse video

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:

  • no-eol: suppress the newline after the last line

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

Constants

This section is empty.

Variables

This section is empty.

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.

Types

This section is empty.

Jump to

Keyboard shortcuts

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