# `Expresso.Highlight`
[🔗](https://github.com/rellen/expresso/blob/main/lib/expresso/highlight.ex#L1)

The highlighting of a code element

`lines/2` makes one HTML fragment for each line of a source text. Makeup
lexes the text when a lexer package or a lexer of `Expresso.Lexers`
registers the language, and it escapes each token. Without a lexer for the language, or without a language, the
function escapes each line and puts it in one `span`, with no class.
`Expresso.CodeVerifier` gives a warning for a language with no lexer.

`stylesheet/0` gives the rules of the token classes, and the renderer writes
them into the document.

Each fragment holds its line break, and no text node of a fragment is only
white space. `Expresso.Deck.render/1` writes the document with Floki, and
Floki drops a text node that is only white space. Therefore the function
puts each white space token into the span of the token before it, and it
puts a zero width space into a line that has no other character.

# `languages`

```elixir
@spec languages() :: [String.t()]
```

Return the name of each language that a lexer registers, in alphabetical order

    iex> "elixir" in Expresso.Highlight.languages()
    true

    iex> "toml" in Expresso.Highlight.languages()
    true

    iex> "cobol" in Expresso.Highlight.languages()
    false

# `lines`

```elixir
@spec lines(String.t(), String.t() | nil, keyword()) :: [String.t()]
```

Make one HTML fragment for each line of the text

The language is a name that a lexer package or `Expresso.Lexers`
registers, such as `"elixir"`, `"js"`, `"rust"` or `"toml"`.
`languages/0` returns each name. A language with no lexer, or no language, gives plain lines.

The option `trailing_comments: false` removes a comment at the end of a
line that has code before it, with the white space before the comment. A
line that is only a comment stays. A text with no lexer keeps its comments,
because only a lexer finds them.

Each fragment starts with a `span` element and ends with one, and the last
`span` holds the line break. Floki removes a text node of white space only,
so the white space of a template around a fragment does not join the text
of the line.

    iex> Expresso.Highlight.lines("a < 1", nil)
    ["<span>a &lt; 1
</span>"]

# `stylesheet`

```elixir
@spec stylesheet() :: String.t()
```

Give the CSS of the token classes, for the class `highlight`

Each color is a custom property of `Expresso.Palette`, such as
`--code-keyword`, so the theme of the deck gives the colors.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
