defmodule Pearly do @moduledoc """ > Pearly Soames wanted gold and silver, but not, in the way of common > thieves, for wealth. He wanted them because they shone and were pure. > Strange, afflicted, and deformed, he sought a cure in the abstract > relation of colors. > -- Mark Helprin, *Winter's Tale* Pearly is an Elixir library for syntax highlighting using Sublime Text syntax definitions. ```elixir Pearly.highlight("html", "
\\n Pearly.highlight("html", "
", format: :terminal)
{:ok, "\\e[48;2;0;43;54m\\e[38;2;88;110;117m<\\e[48;2;0;43;54m\\e[38;2;38;139;210mbr\\e[48;2;0;43;54m\\e[38;2;88;110;117m>"}
"""
@spec highlight(lang, source, [opt]) :: {:ok, String.t} | error
def highlight(lang, source, opts \\ []) do
theme = Keyword.get(opts, :theme, "Solarized (dark)")
format = Keyword.get(opts, :format, :html)
Pearly.Native.highlight(format, lang, theme, source)
receive do
{:pearly_nif_result, :ok, result} ->
{:ok, result}
{:pearly_nif_result, :error, err} ->
{:error, err}
end
end
end