@tanstack/highlight registers every bundled language and exposes a ready-to-use singleton. It also re-exports the public core API.
import {
highlight,
highlightToHtml,
listLanguages,
normalizeLanguage,
renderCodeBlockData,
tokenize,
} from '@tanstack/highlight'A readonly tuple containing all bundled LanguageDefinition objects. Its order is stable and matches listLanguages.
The Highlighter used by every convenience function in this entry point. Its fallback is plaintext.
function normalizeLanguage(lang?: string): HighlightLanguageReturns the canonical registered language name for a name or alias. Names are trimmed and lowercased. Unknown or omitted values resolve to plaintext.
function listLanguages(): Array<HighlightLanguage>Returns the 25 canonical language names registered in defaultHighlighter.
function tokenize(code: string, options?: HighlightOptions): HighlightTokenResultReturns normalized language information and semantic tokens without rendering HTML.
function highlight(code: string, options?: HighlightOptions): HighlightResultReturns code, lang, tokens, and a complete escaped <pre><code> string in html.
function highlightToHtml(code: string, options?: HighlightOptions): stringReturns only the HTML produced by highlight.
function renderCodeBlockData(options: {
code: string
decorations?: HighlightOptions['decorations']
lang?: string
lineNumbers?: boolean
title?: string
}): RenderedCodeBlockDataTrims trailing whitespace from code, highlights it, and returns copyText, htmlMarkup, lang, title, and tokens for a code block component.
A union of every canonical language name included by this entry point. See the language matrix.
The core HighlightResult narrowed so lang is HighlightLanguage.
The core HighlightTokenResult narrowed so lang is HighlightLanguage.
The core RenderedCodeBlockData narrowed so lang is HighlightLanguage.
HighlightOptions plus an optional title.
The default entry also exports createHighlighter, defineLanguage, escapeHtml, renderNodesToHtml, and renderTokens, along with these types: Highlighter, HighlightDecoration, HighlightDecorationData, HighlightElementNode, HighlightLineDecoration, HighlightOptions, HighlightRangeDecoration, HighlightRenderNode, HighlightTextNode, HighlightToken, HighlightTokenClass, LanguageDefinition, TokenRange, and TokenizerContext.
Their contracts are documented in the core reference.