Skip to content

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.

ParameterTypeDescription
options?CreateHighlighterOptionsOptional theme and language configuration.

Promise<Highlighter>

A Highlighter instance ready to tokenize code.

const hl = await createHighlighter();
const tokens = hl.highlight("const x = 1;", "typescript");
// Share across multiple Markdown components
const hl = await createHighlighter({ langs: ["tsx", "python"] });
<Markdown highlight={hl}>{doc1}</Markdown>
<Markdown highlight={hl}>{doc2}</Markdown>

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.

highlight(code, lang?): HighlightToken[][];

Tokenize a code string into styled lines.

ParameterType
codestring
lang?string

HighlightToken[][]

PropertyModifierTypeDescription
loadedLanguagesreadonlystring[]List of currently loaded language grammar IDs.

A single token of highlighted code with optional styling.

PropertyTypeDescription
bold?booleanWhether the token should be rendered bold.
color?stringForeground color — either a Glyph named color or a hex string.
contentstringThe text content of the token.
italic?booleanWhether the token should be rendered italic.
underline?booleanWhether the token should be rendered with underline.

PropertyTypeDescription
langs?BundledLanguage[]Languages to load. Defaults to a common set.
theme?BundledThemeShiki theme name. When omitted, uses a built-in terminal-native theme that outputs ANSI named colors (inherits from the terminal palette).