Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pangoraw/treesitterhighlight.jl
Static HTML highlighting using tree-sitter
https://github.com/pangoraw/treesitterhighlight.jl
Last synced: 26 days ago
JSON representation
Static HTML highlighting using tree-sitter
- Host: GitHub
- URL: https://github.com/pangoraw/treesitterhighlight.jl
- Owner: Pangoraw
- License: mit
- Created: 2022-03-30T23:13:02.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-05-02T19:24:35.000Z (over 2 years ago)
- Last Synced: 2024-10-10T17:49:50.880Z (28 days ago)
- Language: Julia
- Homepage:
- Size: 4.21 MB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TreeSitterHighlight.jl
> [🌠View this readme rendered using TreeSitterHighlight.jl!](https://htmlview.glitch.me/?https://gist.github.com/Pangoraw/9ffaff45a2a0165dc9f10a6fdc116660)
A Julia package to export static HTML for highlighted code based on [`tree-sitter/highlight`](https://github.com/tree-sitter/tree-sitter/tree/master/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.```julia
using TreeSitterHighlight, tree_sitter_javascript_jllhighlighter = 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)
endhighlight_js_code("""
function main(msg) {
console.log(msg)
}
""")
```## Gallery
This readme is using a [Pluto](https://github.com/JuliaPluto/Pluto.jl) inspired theme and all the code highlighting is made using TreeSitterHighlight.jl!
### Javascript
```javascript
/**
* Prints an hello world message to the console
**/
function main() {
let world = "world"
const message = `Hello, ${world} !`;
console.log(message);
}main();
```