Default Entry
Default Entry#
@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'Values#
allLanguages#
A readonly tuple containing all bundled LanguageDefinition objects. Its order is stable and matches listLanguages.
defaultHighlighter#
The Highlighter used by every convenience function in this entry point. Its fallback is plaintext.
Functions#
normalizeLanguage#
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.
listLanguages#
function listLanguages(): Array<HighlightLanguage>Returns the 39 canonical language names registered in defaultHighlighter.
tokenize#
function tokenize(code: string, options?: HighlightOptions): HighlightTokenResultReturns normalized language information and semantic tokens without rendering HTML.
highlight#
function highlight(code: string, options?: HighlightOptions): HighlightResultReturns code, lang, tokens, and a complete escaped <pre><code> string in html.
highlightToHtml#
function highlightToHtml(code: string, options?: HighlightOptions): stringReturns only the HTML produced by highlight.
renderCodeBlockData#
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.
Types#
HighlightLanguage#
A union of every canonical language name included by this entry point. See the language matrix.
HighlightResult#
The core HighlightResult narrowed so lang is HighlightLanguage.
HighlightTokenResult#
The core HighlightTokenResult narrowed so lang is HighlightLanguage.
RenderedCodeBlockData#
The core RenderedCodeBlockData narrowed so lang is HighlightLanguage.
RenderCodeBlockOptions#
HighlightOptions plus an optional title.
Core re-exports#
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.
Importing only these core helpers lets a compatible bundler remove the all-language registry. The bound convenience functions above retain it.