View Source Autumn (Autumn v0.1.4)

Autumn logo

Syntax highlighter for source code parsed with Tree-Sitter and styled with Helix Editor themes.

Hex Version Hex Docs MIT

Features

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" style="background-color: #282C34; color: #ABB2BF;">
#=> <code class="language-elixir" translate="no">
#=> <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="" style="color: #ABB2BF;">(</span><span class="string" style="color: #98C379;">:elixir</span><span class="" style="color: #ABB2BF;">)</span>
#=> </code></pre>

Autumn.highlight!("rb", "Math.sqrt(9)", theme: "dracula") |> IO.puts()
#=> <pre class="autumn highlight" style="background-color: #282A36; color: #f8f8f2;">
#=> <code class="language-ruby" translate="no">
#=> <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:

Elixir source code in onedark themeElixir source code in github_light theme

Looking for help with your Elixir project?

DockYard logo

At DockYard we are ready to help you build your next Elixir project. We have a unique expertise in Elixir and Phoenix development that is unmatched and we love to write about Elixir.

Have a project in mind? Get in touch!

Acknowledgements

Summary

Types

A language name, filename, or extesion.

Functions

Highlights the source_code using the tree-sitter grammar for lang_filename_ext.

Types

@type lang_filename_ext() :: String.t() | nil

A language name, filename, or extesion.

Examples

- "elixir"
- "main.rb"
- ".rs"
- "php"

An invalid language or nil will fallback to rendering plain text using the background and foreground colors defined by the current theme.

Functions

Link to this function

highlight(lang_filename_ext, source_code, opts \\ [])

View Source
@spec highlight(lang_filename_ext(), String.t(), keyword()) ::
  {:ok, String.t()} | {:error, term()}

Highlights the source_code using the tree-sitter grammar for 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 pass theme: "adwaita_dark" to use the Adwaita Dark theme or pass theme: "penumbra" to use the Penumbra+ theme, and so on.
  • :pre_class (default: "autumn highlight") - the CSS class to inject into the <pre> tag.
  • :code_class (deafult: nil) - the CSS class to inject into the <code> tag, it's dynamically generated as "language-{name} when the value is nil.
Link to this function

highlight!(lang_filename_ext, source_code, opts \\ [])

View Source
@spec highlight!(lang_filename_ext(), String.t(), keyword()) :: String.t()

Same as highlight/3 but raises in case of failure.