diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..314acf9 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +# Changelog + +## v1.0.0 - 2025-04-01 + +- Initial release. diff --git a/README.md b/README.md index 444a1ba..31c570a 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,58 @@ -# just +# Just + +A JavaScript lexer and syntax highlighter for Gleam! [](https://hex.pm/packages/just) [](https://hexdocs.pm/just/) +Just is a JavaScript lexer and syntax highlighter written in Gleam. +The `just` module, based on [`glexer`](https://hexdocs.mp/glexer) exposes a +standard lexer API, allowing you to convert JavaScript source code into tokens. +The `just/highlight` module allows you to highlight javascript code using ansi +colours, html or a custom format. Heavily inspired by [`contour`](https://hexdocs.pm/contour). + ```sh gleam add just@1 ``` + ```gleam import just +import just/highlight + +pub fn main() { + let code = "console.log('Hello, world!');" + + let lexer = just.new(code) |> just.strict_mode + // Lex syntax tokens for parsing or other uses + let #(tokens, errors) = just.tokenise(lexer) + let assert [] = errors + parse_js(tokens) -pub fn main() -> Nil { - // TODO: An example of the project in use + // Highlight with ansi codes to print in the terminal + let highlighted = highlight.ansi(code) + io.println(highlighted) + + // Render to html to show in the browser + let html = highlight.html(code) + io.println("
" <> html <> "")
+
+ // Convert to "highlighting tokens" to highlight in some other way
+ let highlight_tokens = highlight.tokens(code)
+ highlight_tokens_some_other_way(highlight_tokens)
}
```
Further documentation can be found at