Skip to content

zidane-ui/code/tokens

import { … } from 'zidane-ui/code/tokens'ui/src/code/tokens.ts

Functions#

highlightToTokensFunction#

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.

TypeScript
function highlightToTokens(
  code: string,
  lang: string,
  themeId: string,
): Promise<CodeTokens | null>
Parameters
NameTypeDescription
codestring

The code.

langstring

A language name or alias, such as ts or shellscript.

themeIdstring

A bundled code theme id (code-themes.ts).

Promise<CodeTokens | null>

The runs, or null for a language with no lexer or an unknown theme.

ui/src/code/highlights.ts:65

Interfaces#

CodeRunInterface#

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

TypeScript
interface CodeRun
CodeRun properties
NameTypeDescription
bold?true

Drawn bold.

color?string

Its color, #rrggbb; absent: the theme's text color.

italic?true

Drawn italic.

textstring

The run's text.

ui/src/code/highlights.ts:36

CodeTokensInterface#

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

TypeScript
interface CodeTokens
CodeTokens properties
NameTypeDescription
bg?string

The theme's background color.

fg?string

The theme's text color.

linesCodeRun[][]

Each line's runs, in order.

ui/src/code/highlights.ts:48

Re-exports#

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