william
william is a TOML lexer and syntax highlighter for Gleam. It parses TOML source
into a recoverable token stream and can render those tokens as ANSI or HTML.
The name comes from William Hanna, one of the original Tom & Jerry creators alongside Joseph Barbera.
gleam add william@1
import gleam/io
import william
pub fn main() -> Nil {
let html =
"name = \"TOML\"\n"
|> william.highlight
|> william.to_html
io.println(html)
}
HTML classes
to_html uses contour-style classes:
| Token | CSS class |
|---|---|
| Comment | hl-comment |
| Date/time | hl-function |
| Error | hl-error |
| Key | hl-attribute |
| Literal | hl-literal |
| Number | hl-number |
| Operator | hl-operator |
| Punctuation | hl-punctuation |
| String | hl-string |
| Table name | hl-module |
| Whitespace | no class |
pre code {
.hl-comment { color: #d4d4d4; font-style: italic }
.hl-function { color: #9ce7ff }
.hl-attribute { color: #ffd596 }
.hl-operator { color: #ffaff3 }
.hl-string { color: #c8ffa7 }
.hl-number { color: #c8ffa7 }
.hl-literal { color: #c8ffa7 }
.hl-module { color: #ffddfa }
.hl-punctuation { color: inherit }
.hl-error { background: red; color: white }
}
Further documentation can be found at https://hexdocs.pm/william.
Development
gleam dev # Highlight this package's gleam.toml
gleam run # Run the project
gleam test # Run the tests