Marcli.Formatter
(Marcli v0.3.1)
View Source
Makeup formatter that produces ANSI-escaped terminal output.
Maps Makeup token types (:keyword, :string, :comment, etc.) to ANSI
escape sequences using a configurable style map from Marcli.Theme.
Standalone usage with Makeup
theme = Marcli.Theme.default()
Makeup.highlight(source,
lexer: "elixir",
formatter: Marcli.Formatter,
formatter_options: [syntax: theme.syntax, reset: theme.reset]
)Token type fallback
When a specific token type (e.g. :keyword_constant) is not present in
the style map, the formatter walks up the hierarchy by stripping trailing
segments: :keyword_constant -> :keyword -> unstyled.
Summary
Functions
Formats a list of Makeup tokens as an ANSI-escaped binary string.
Formats a list of Makeup tokens as an iolist with ANSI escape sequences.
Same as format_as_binary/2 (no wrapping needed for terminal output).
Same as format_as_iolist/2 (no wrapping needed for terminal output).
Formats a single Makeup token {tag, meta, value} into a string.
Types
Functions
Formats a list of Makeup tokens as an ANSI-escaped binary string.
Options
:syntax-- map of token types to ANSI escape sequences (default:Marcli.Theme.default().syntax):reset-- ANSI reset sequence (default:"\e[0m")
Formats a list of Makeup tokens as an iolist with ANSI escape sequences.
Accepts the same options as format_as_binary/2.
Same as format_as_binary/2 (no wrapping needed for terminal output).
Same as format_as_iolist/2 (no wrapping needed for terminal output).
Formats a single Makeup token {tag, meta, value} into a string.
Looks up the ANSI sequence for tag in syntax, falling back through
parent types. Handles newlines within token values by resetting and
re-opening the style at each line boundary.