# zidane-ui/code/tokens

Import: `import { … } from 'zidane-ui/code/tokens'`. Source: [ui/src/code/tokens.ts](https://github.com/Tahul/zidane/blob/main/ui/src/code/tokens.ts).

## Functions

### `highlightToTokens`

Function.

Code highlighting for a host that draws code itself (the phone, in native text): the same
highlighter and themes as the kit's code blocks (`@pierre/highlights`), giving lines of styled
runs instead of HTML. It runs where WebAssembly does (a web view), so it is an entry of its own:
that page loads this and nothing else.

```ts
function highlightToTokens(
  code: string,
  lang: string,
  themeId: string,
): Promise<CodeTokens | null>
```

**Parameters**

- `code` (`string`): The code.
- `lang` (`string`): A language name or alias, such as `ts` or `shellscript`.
- `themeId` (`string`): A bundled code theme id (`code-themes.ts`).

**Returns** `Promise<CodeTokens | null>`: The runs, or `null` for a language with no lexer or an unknown theme.

Source: [ui/src/code/highlights.ts:65](https://github.com/Tahul/zidane/blob/main/ui/src/code/highlights.ts#L65)

## Interfaces

### `CodeRun`

Interface.

One styled run of a line: its text, its color (`#rrggbb`, absent: the theme's text), bold and italic.

```ts
interface CodeRun
```

**Properties**

- `bold?` (`true`): Drawn bold.
- `color?` (`string`): Its color, `#rrggbb`; absent: the theme's text color.
- `italic?` (`true`): Drawn italic.
- `text` (`string`): The run's text.

Source: [ui/src/code/highlights.ts:36](https://github.com/Tahul/zidane/blob/main/ui/src/code/highlights.ts#L36)

### `CodeTokens`

Interface.

Code as lines of styled runs, and the theme's text and background colors.

```ts
interface CodeTokens
```

**Properties**

- `bg?` (`string`): The theme's background color.
- `fg?` (`string`): The theme's text color.
- `lines` (`CodeRun[][]`): Each line's runs, in order.

Source: [ui/src/code/highlights.ts:48](https://github.com/Tahul/zidane/blob/main/ui/src/code/highlights.ts#L48)

## Re-exports

These names are documented on the entry point that owns them.

- [code/shiki-theme](https://zidane.si/docs/reference/ui-code-shiki-theme.md): [`shikiThemeFor`](https://zidane.si/docs/reference/ui-code-shiki-theme.md#shikiThemeFor)
