TreeSitterHighlight.jl

Static HTML highlighting using tree-sitter
Author Pangoraw
Popularity
1 Star
Updated Last
2 Years Ago
Started In
March 2022

TreeSitterHighlight.jl

🌠 View this readme rendered using TreeSitterHighlight.jl!

A Julia package to export static HTML for highlighted code based on tree-sitter/highlight.

Usage

To highlight a source file, you will need:

  • A Tree-sitter language.
  • Highlights queries that return category for matches.
  • Injections queries that specify when the language should switch.
using TreeSitterHighlight, tree_sitter_javascript_jll

highlighter = Highlighter(Dict(
    "keyword" => "class=keyword",
))

libts_js = tree_sitter_javascript_jll.libtreesitter_javascript_path

language = Language(
    :javascript,
    @ccall libts_js.tree_sitter_javascript()::Ptr{Nothing}
)

scope = "source.js"

add_language!(
    highlighter,
    language;
    scope,
    injection_regex,
    highlights_query,
    injections_query,
    locals_query,
)

function highlight_js_code(code::String)::String
    TreeSitterHighlight.highlight(highlighter, code; scope)
end

highlight_js_code("""
function main(msg) {
    console.log(msg)
}
""")

Gallery

This readme is using a Pluto inspired theme and all the code highlighting is made using TreeSitterHighlight.jl!

Javascript

/**
 * Prints an hello world message to the console
 **/
function main() {
    let world = "world"
    const message = `Hello, ${world} !`;
    console.log(message);
}

main();

Required Packages

Used By Packages

No packages found.