View Source AnsiToHTML (AnsiToHTML v0.6.0)

AnsiToHTML is a small library to convert ANSI Styling codes to HTML using phoenix_html. The library is not solely intended for use with Phoenix and can be easily used without it.

Link to this section Summary

Functions

Generates a new HTML string based on the passed ANSI string.

Generates a new Phoenix HTML tag based on the passed ANSI string.

Link to this section Functions

Link to this function

generate_html(input, theme \\ %AnsiToHTML.Theme{})

View Source
@spec generate_html(String.t(), AnsiToHTML.Theme.t()) :: String.t()

Generates a new HTML string based on the passed ANSI string.

Returns String.t.

examples

Examples

iex> AnsiToHTML.generate_html(inspect :hello, pretty: true, syntax_colors: [atom: :green])
"<pre style=\"font-family: monospace; font-size: 12px; padding: 4px; background-color: black; color: white;\"><span style=\"color: green;\">:hello</span></pre>"
Link to this function

generate_phoenix_html(input, theme \\ %AnsiToHTML.Theme{})

View Source
@spec generate_phoenix_html(String.t(), AnsiToHTML.Theme.t()) :: Phoenix.HTML.Tag.t()

Generates a new Phoenix HTML tag based on the passed ANSI string.

Returns Phoenix.HTML.Tag.t.

examples

Examples

iex> AnsiToHTML.generate_phoenix_html(inspect :hello, pretty: true, syntax_colors: [atom: :green])
{:safe,
[60, "pre",
  [32, "style", 61, 34,
    "font-family: monospace; font-size: 12px; padding: 4px; background-color: black; color: white;",
    34], 62,
  [[60, "span", [32, "style", 61, 34, "color: green;", 34], 62, [":hello"],
    60, 47, "span", 62]], 60, 47, "pre", 62]}