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.
function createCodeHighlighter(options?: CodeHighlighterOptions): CodeHighlighterParameters
| Name | Type | Default | Description |
|---|---|---|---|
| options? | CodeHighlighterOptions | {} |
Returns
Interfaces#
CodeHighlighterInterface#
Highlights code to HTML, with a result cache. Create one per app with createCodeHighlighter.
interface CodeHighlighterProperties
| Name | Type | Description |
|---|---|---|
| cached | (code: string, lang: string, theme: string) => string | null | undefined | The settled result of an earlier |
| highlight | (code: string, lang: string, theme: string) => Promise<string | null> | Highlights code, or returns the cached result. |
CodeHighlighterOptionsInterface#
Options of createCodeHighlighter.
interface CodeHighlighterOptionsProperties
| Name | Type | Description |
|---|---|---|
| createWorker? | () => Worker | Starts a worker running |
HighlightRequestInterface#
A request to the highlighting worker.
interface HighlightRequestProperties
| Name | Type | Description |
|---|---|---|
| code | string | The code. |
| id | number | Correlates the response. |
| lang | string | A language name or alias. |
| theme | string | A bundled code theme id. |
HighlightResponseInterface#
The highlighting worker's answer to a HighlightRequest.
interface HighlightResponseProperties
| Name | Type | Description |
|---|---|---|
| html | string | null | The highlighted HTML, or |
| id | number | The request's id. |