Skip to main content

README.md

# william

[![Package Version](https://img.shields.io/hexpm/v/william)](https://hex.pm/packages/william)
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/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.

```sh
gleam add william@1
```
```gleam
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       |

```css
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

```sh
gleam dev   # Highlight this package's gleam.toml
gleam run   # Run the project
gleam test  # Run the tests
```