View Source TreeSitterHighlight (Elixir Tree Sitter Highlight v0.2.2)

Elixir binding for https://docs.rs/tree-sitter-highlight/latest/tree_sitter_highlight/

Summary

Functions

Returns CSS content with classes for highlighting and formatting html output. See priv/default.css for an example of how to create your own stylesheet. This stylesheet contains both a light and dark color scheme. To toggle the dark scheme set data-theme="dark" on the root <html> element.

Returns a language atom for the file, or nil if the language isn't supported.

Returns a list of supported language atoms.

Renders the given source code into html.

Writes a complete html document with highlighted code within. head_content should contain a stylesheet.

Functions

Link to this function

get_default_css_content()

View Source

Returns CSS content with classes for highlighting and formatting html output. See priv/default.css for an example of how to create your own stylesheet. This stylesheet contains both a light and dark color scheme. To toggle the dark scheme set data-theme="dark" on the root <html> element.

Link to this function

get_language_from_filename(filename)

View Source

Returns a language atom for the file, or nil if the language isn't supported.

Examples

iex> TreeSitterHighlight.get_language_from_filename("/path/file.ex")
:elixir

iex> TreeSitterHighlight.get_language_from_filename("/path/file.txt")
nil
Link to this function

get_supported_languages()

View Source

Returns a list of supported language atoms.

Link to this function

render_html(source_code, language_atom)

View Source

Renders the given source code into html.

Examples

iex> TreeSitterHighlight.render_html("1", :elixir)
{:ok, "<pre class=\"code-block language-elixir\"><code>\n<div class=\"line-wrapper\"><span class=\"line-number\">1</span><span class=\"token number\">1</span>\n</div>\n</code></pre>\n"}

iex> TreeSitterHighlight.render_html("1", :txt)
{:error, :unsupported_language}
Link to this function

write_highlighted_file(input_path, output_path, head_content)

View Source

Writes a complete html document with highlighted code within. head_content should contain a stylesheet.

Example

iex> TreeSitterHighlight.write_highlighted_file(
...> "lib/tree_sitter_highlight.ex",
...> "example_output/ex_tree_sitter_highlight/tree_sitter_highlight.html",
...> "<style>#{TreeSitterHighlight.get_default_css_content()}</style>"
...> )
:ok