Boxart.Highlight (Boxart v0.3.1)

Copy Markdown View Source

ANSI terminal formatter for Makeup syntax highlighting tokens.

Maps Makeup {type, metadata, text} token types to ANSI escape sequences using a dark terminal color scheme.

Summary

Functions

Converts Makeup tokens to [{text, style}] pairs.

Tokenizes and formats source code with ANSI colors.

Returns a single ANSI-colored string for the given source and language.

Types

styled_segment()

@type styled_segment() :: {String.t(), String.t()}

Functions

format_tokens(tokens)

@spec format_tokens([{atom(), keyword(), String.t() | [any()]}]) :: [styled_segment()]

Converts Makeup tokens to [{text, style}] pairs.

highlight(source, language)

@spec highlight(String.t(), atom()) :: [styled_segment()]

Tokenizes and formats source code with ANSI colors.

Returns a list of {text, ansi_style} tuples. If Makeup or the requested lexer is unavailable, returns the source as-is with an empty style.

to_ansi_string(source, language)

@spec to_ansi_string(String.t(), atom()) :: String.t()

Returns a single ANSI-colored string for the given source and language.