Tokens

Renders syntax highlighted tokens for the CodeBlock component.

API Reference

Tokens

({ children, language: languageProp, allowErrors, showErrors, shouldAnalyze: shouldAnalyzeProp, shouldFormat, renderLine, css: cssProp, className, style, }: TokensProps) => Promise<React.JSX.Element>

Renders syntax highlighted tokens for the CodeBlock component.

Parameters
TokensProps
Returns
Promise<Element>

TokensProps

TokensProps
Properties

children

string | Promise<string> | undefined

Code string to highlight and render as tokens.

allowErrors

string | boolean | undefined

Whether to allow errors to be displayed.

showErrors

boolean | undefined

Whether to show errors.

shouldAnalyze

boolean | undefined

Whether or not to analyze the source code for type errors and provide quick information on hover.

shouldFormat

boolean | undefined

Whether or not to format the source code using prettier if installed.

language

Languages | undefined

Language to use for syntax highlighting.

css

{ token?: CSSObject; popover?: CSSObject; } | undefined

CSS style object to apply to the tokens and popover elements.

className

{ token?: string; popover?: string; } | undefined

Class names to apply to the tokens and popover elements.

style

{ token?: React.CSSProperties; popover?: React.CSSProperties; } | undefined

Styles to apply to the tokens and popover elements.

renderLine

((line: { children: React.ReactNode; index: number; isLast: boolean; }) => React.ReactNode) | undefined

Custom render function for each line of tokens.