View Source Autumn (Autumn v0.1.1)
Syntax highlighter for source code parsed with Tree-Sitter and styled with Helix Editor themes.
Support multiple languages and 100+ themes. See some samples at https://autumn-30n.pages.dev
Use Rust's inkjet crate under the hood.
Installation
Add :autumn
dependency:
def deps do
[
{:autumn, "~> 0.1"}
]
end
Usage
Autumn.highlight!("elixir", "Atom.to_string(:elixir)") |> IO.puts()
#=> <pre class="autumn highlight background" style="background-color: #282C34; ">
#=> <code class="language-elixir">
#=> <span class="namespace" style="color: #61AFEF; ">Atom</span>
#=> <span class="operator" style="color: #C678DD; ">.</span>
#=> <span class="function" style="color: #61AFEF; ">to_string</span>
#=> <span class="text" style="color: #ABB2BF; ">(</span>
#=> <span class="string" style="color: #98C379; ">:elixir</span>
#=> <span class="text" style="color: #ABB2BF; ">)</span>
#=> </code></pre>
Autumn.highlight!("rb", "Math.sqrt(9)", theme: "dracula") |> IO.puts()
#=> <pre class="autumn highlight background" style="background-color: #282A36; ">
#=> <code class="language-rb">
#=> <span class="constructor" style="color: #BD93F9; ">Math</span>
#=> <span class="punctuation delimiter" style="color: #f8f8f2; ">.</span>
#=> <span class="function method" style="color: #50fa7b; ">sqrt</span>
#=> <span class="punctuation bracket" style="color: #f8f8f2; ">(</span>
#=> <span class="constant numeric" style="color: #BD93F9; ">9</span>
#=> <span class="punctuation bracket" style="color: #f8f8f2; ">)</span>
#=> </code></pre>
Samples
Visit https://autumn-30n.pages.dev to see all available samples like the ones below:
Summary
Types
A language name, filename, or extesion.
Functions
Highlight the source_code
with the rules of lang_filename_ext
.
Same as highlight/3
but raises in case of failure.
Types
@type lang_filename_ext() :: String.t()
A language name, filename, or extesion.
The following values are valid to highlight an Elixir source code:
- "elixir", "my_module.ex", "my_script.exs", "ex", "exs"
And any other language can be highlighted in the same way.
Functions
@spec highlight(lang_filename_ext(), String.t(), keyword()) :: {:ok, String.t()} | {:error, term()}
Highlight the source_code
with the rules of lang_filename_ext
.
Options
:theme
(default"onedark"
) - accepts any theme listed here, you should pass the filename without special chars and without extension, for example you should passtheme: "adwaita_dark"
to use the Adwaita Dark theme.:pre_class
(default:"autumn highlight"
) - the CSS class to inject into the<pre>
tag.
@spec highlight!(lang_filename_ext(), String.t(), keyword()) :: String.t()
Same as highlight/3
but raises in case of failure.