createHighlighter
function createHighlighter(options?): Promise<Highlighter>;Create a syntax highlighter backed by Shiki (TextMate grammars).
By default uses a terminal-native theme whose colors adapt to your
terminal palette. Pass a theme name to use a Shiki built-in theme
with fixed hex colors instead.
The <Markdown> component handles this automatically — you only need
createHighlighter when sharing a single instance across multiple
components or when you need manual control.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options? | CreateHighlighterOptions | Optional theme and language configuration. |
Returns
Section titled “Returns”Promise<Highlighter>
A Highlighter instance ready to tokenize code.
Examples
Section titled “Examples”const hl = await createHighlighter();const tokens = hl.highlight("const x = 1;", "typescript");// Share across multiple Markdown componentsconst hl = await createHighlighter({ langs: ["tsx", "python"] });<Markdown highlight={hl}>{doc1}</Markdown><Markdown highlight={hl}>{doc2}</Markdown>Highlighter
Section titled “Highlighter”A syntax highlighter instance that tokenizes code strings.
Created via createHighlighter. Can be passed to the <Markdown>
component’s highlight prop to share a single Shiki instance across
multiple renders.
Methods
Section titled “Methods”highlight()
Section titled “highlight()”highlight(code, lang?): HighlightToken[][];Tokenize a code string into styled lines.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
code | string |
lang? | string |
Returns
Section titled “Returns”HighlightToken[][]
Properties
Section titled “Properties”| Property | Modifier | Type | Description |
|---|---|---|---|
loadedLanguages | readonly | string[] | List of currently loaded language grammar IDs. |
HighlightToken
Section titled “HighlightToken”A single token of highlighted code with optional styling.