Skip to content

code/highlighter

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

Functions#

createCodeHighlighterFunction#

Creates a highlighter with its own cache and, given a factory, its own worker.

TypeScript
function createCodeHighlighter(options?: CodeHighlighterOptions): CodeHighlighter
Parameters
NameTypeDefaultDescription
options?CodeHighlighterOptions{}

The CodeHighlighterOptions.

ui/src/code/highlighter.ts:138

Interfaces#

CodeHighlighterInterface#

Highlights code to HTML, with a result cache. Create one per app with createCodeHighlighter.

TypeScript
interface CodeHighlighter
CodeHighlighter properties
NameTypeDescription
cached(code: string, lang: string, theme: string) => string | null | undefined

The settled result of an earlier CodeHighlighter.highlight, read synchronously, so a block highlighted before paints colored on its first frame.

highlight(code: string, lang: string, theme: string) => Promise<string | null>

Highlights code, or returns the cached result.

ui/src/code/highlighter.ts:46

CodeHighlighterOptionsInterface#

Options of createCodeHighlighter.

TypeScript
interface CodeHighlighterOptions
CodeHighlighterOptions properties
NameTypeDescription
createWorker?() => Worker

Starts a worker running zidane-ui/code/highlight.worker. Called once, on the first highlight. Without it, highlighting runs on the main thread.

ui/src/code/highlighter.ts:37

HighlightRequestInterface#

A request to the highlighting worker.

TypeScript
interface HighlightRequest
HighlightRequest properties
NameTypeDescription
codestring

The code.

idnumber

Correlates the response.

langstring

A language name or alias.

themestring

A bundled code theme id.

ui/src/code/highlighter.ts:17

HighlightResponseInterface#

The highlighting worker's answer to a HighlightRequest.

TypeScript
interface HighlightResponse
HighlightResponse properties
NameTypeDescription
htmlstring | null

The highlighted HTML, or null for a language with no lexer.

idnumber

The request's id.

ui/src/code/highlighter.ts:29