Localize.Message.Formatter (Localize v1.4.3)

Copy Markdown View Source

Dispatch module for rendering MF2 highlight tokens.

Delegates to one of the format-specific formatter modules based on the :format option:

Summary

Functions

Renders a token list in the chosen format.

Types

format()

@type format() :: :plain | :html | :ansi

Functions

render(tokens, format, options \\ [])

@spec render([Localize.Message.Highlighter.token()], format(), Keyword.t()) ::
  String.t() | {:error, Exception.t()}

Renders a token list in the chosen format.

Arguments

  • tokens is a list of t:Highlighter.token/0 tuples.

  • format is one of :plain, :html, or :ansi.

  • options is a keyword list of format-specific options.

Returns

  • A rendered string.

Examples

iex> {:ok, ast} = Localize.Message.Parser.parse("Hello {$name}!")
iex> tokens = Localize.Message.Highlighter.to_tokens(ast)
iex> Localize.Message.Formatter.render(tokens, :plain)
"Hello {$name}!"