# orca.highlight

> A module of morca's API.

Mojo source coloured for the UI's code-on-hover (`_PEEK` in `orca.ui.layout`), on the server, with no library: `tokens` splits source into runs of one kind, and `highlight` turns those into HTML lines with a `<span>` per coloured run.

```
var lines = highlight(src)      # one HTML string per source line
```

The kinds, each a class `hl--<kind>` the stylesheet colours from its
tokens (so both themes have them):

| Kind | What |
|---|---|
| `kw` | a keyword: `def`, `struct`, `var`, `comptime`, `if`, `return`, ... |
| `str` | a string, `"..."`, `'...'` or triple-quoted over several lines |
| `com` | a comment, `#` to the end of the line |
| `num` | a number: `42`, `1_000`, `0x1f`, `3.5e-2` |
| `dec` | a decorator, `@fieldwise_init` |
| `fn` | the name a `def`, `fn`, `struct` or `trait` defines |
| `const` | `True`, `False`, `None`, `self`, `Self` |

Anything else is plain text. A string or comment never holds a span open
across a line: each line's HTML is whole, so the hover can show any slice
of them. It's a highlighter, not a parser: an unterminated string runs to
the end of its line (or, triple-quoted, of the file).

## Structs

### `Token`

```mojo
struct Token
```

A run of source of one kind: bytes `start` to `end`.

Implements: `Copyable`, `Movable`

Fields:

- `kind: StaticString`
- `start: Int`
- `end: Int`

## Functions

### `tokens`

```mojo
def tokens(src: StringSpan) -> List[Token]
```

`src` as runs of one kind each, in order, covering every byte.

### `highlight`

```mojo
def highlight(src: StringSpan) -> List[String]
```

`src` as HTML, a string per line (split at `\n`, without it), each coloured run a `<span class="hl hl--<kind>">`, everything escaped.

## Aliases

### `PLAIN`

```mojo
comptime PLAIN = ""
```

### `KEYWORD`

```mojo
comptime KEYWORD = "kw"
```

### `STRING`

```mojo
comptime STRING = "str"
```

### `COMMENT`

```mojo
comptime COMMENT = "com"
```

### `NUMBER`

```mojo
comptime NUMBER = "num"
```

### `DECORATOR`

```mojo
comptime DECORATOR = "dec"
```

### `NAME`

```mojo
comptime NAME = "fn"
```

### `CONSTANT`

```mojo
comptime CONSTANT = "const"
```
