william

Package VersionHex Docs

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:

TokenCSS class
Commenthl-comment
Date/timehl-function
Errorhl-error
Keyhl-attribute
Literalhl-literal
Numberhl-number
Operatorhl-operator
Punctuationhl-punctuation
Stringhl-string
Table namehl-module
Whitespaceno 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