spruce/markdown

Markdown to ANSI terminal rendering.

Rendering is driven by the mork parser (canonical home: https://git.liten.app/krig/mork) and walks its document AST directly rather than going through mork’s HTML output.

GFM support

The following GitHub Flavored Markdown extensions are supported:

In addition, GitHub-style alerts (> [!NOTE], [!TIP], [!IMPORTANT], [!WARNING], [!CAUTION]) and Astro/Starlight :::type[Title] container directives are rendered as colored callouts.

Known limitations

These are GitHub/Markdown features that are not rendered. Most stem from upstream mork (tracked in its TODO.md); a few are deliberate choices here.

Types

Markdown rendering options: the theme and an optional wrap width.

pub opaque type Options

A set of styles controlling how each Markdown element is rendered. Construct one with dark_theme, light_theme, or adaptive_theme.

pub opaque type Theme

Values

pub fn adaptive_theme() -> Theme

A theme whose colors adapt to the terminal background (light vs dark), resolved per render from spruce.background. This is the default theme used by render and default_options. On Unknown backgrounds it renders as dark.

pub fn dark_theme() -> Theme

Build a theme tuned for dark terminal backgrounds.

pub fn default_options() -> Options

Default options: the adaptive theme and no width limit.

pub fn light_theme() -> Theme

Build a theme tuned for light terminal backgrounds.

pub fn print(sp: spruce.Spruce, markdown: String) -> Nil

Render Markdown with the default options and print it to stdout.

pub fn render(sp: spruce.Spruce, markdown: String) -> String

Render Markdown to styled terminal text using the default options.

pub fn render_with(
  sp: spruce.Spruce,
  markdown: String,
  options: Options,
) -> String

Render Markdown to styled terminal text with explicit options.

pub fn with_theme(options: Options, theme: Theme) -> Options

Use a specific theme when rendering.

pub fn with_width(options: Options, width: Int) -> Options

Wrap rendered output to a maximum visual width. Negative values clamp to 0.

Search Document