The component can be imported via:
The CodeBlock component requires two arguments:
code - a string of code to be shownlanguage - the language of the codeThe component uses Shiki for syntax highlighting, and language must be
one of the languages it supports.
The CodeBlock component supports all themes supported by Shiki.
They will be loaded lazily when the component is rendered.
To change the theme or display mode, the following props are available:
lightTheme - the theme to use when the mode is light (by default, catppuccin-latte)darkTheme - the theme to use when the mode is dark (by default, catppuccin-mocha)mode - the display mode to use (by default, dark)The same values can be configured for every CodeBlock under a PlumaProvider with componentConfig.PlumaCodeBlock.
Set shouldMatchColorScheme to use the provider's resolved light or dark color scheme as the CodeBlock mode.
An explicit prop on a CodeBlock still overrides the provider-level default.
For example, to use the default light mode, simply set mode to light.
By default, the component renders a "Copy to clipboard" button. This can be
disabled by setting withCopyButton to false.
export function Example() {
return <div>Hello, world!</div>;
}The component supports showing line numbers in the left gutter by setting withLineNumbers to true.
Additionally, it's possible to specify the starting line number with startLineNumber - in case
the code block is not starting from line 1.
For JSON code blocks, the component supports collapsing/expanding nested blocks.
When language is json this is enabled by default, but can be disabled by setting withLineFoldingControls to false.
The component supports highlighting specific lines and/or parts of lines via the
highlights prop.
It accepts an array with values of the following types:
[number, number] tuple - highlights a range of lines (inclusive){ line: number } - highlights a specific line{ lines: [number, number] | [number, number][] } - highlights a range or multiple ranges of lines{ line: number, columns: [number, number] | [number, number][] } - highlights specific columns in a line
Similar to highlights, the component supports inserting label-like elements into
the code block to highlight sections that should be replaced with other values.
It accepts an array of objects with the following keys:
line - the line number to insert the label atcolumn - the column number to insert the label atvalue - the string value to insert into the labelThe inserted variable labels won't be included in the content when the code block is copied to the clipboard.
PlumaCodeBlock extends BoxThe code to be formatted
Default:'catppuccin-mocha'
The theme to use for syntax highlighting when mode is dark.
Must be one of the themes supported by Shiki.
Highlight specific lines and/or columns. Multiple formats are supported:
[number, number] tuple - highlights a range of lines (inclusive){ line: number } - highlights a specific line{ lines: [number, number] | [number, number][] } - highlights a range or multiple ranges of lines{ line: number, columns: [number, number] | [number, number][] } - highlights specific columns in a line
Default:true
By default the code block renders with rounded corners, but you can disable this in case you need to embed it elsewhere with matching styling.
The language to use for syntax highlighting. Must be one of the languages supported by Shiki.
When showing the language label, the component will use the language's displayName
retrieved from Shiki.
If you want to override the value, you can provide one with languageDisplayName.
Default:'catppuccin-latte'
The theme to use for syntax highlighting when mode is light.
Must be one of the themes supported by Shiki.
Default:dark
What theme mode to use.
Default:1
Number of the first line.
Insert tag-like variables into the code block to highlight sections
that should be replaced with other values.
As opposed to highlights, the inserted variable tags won't be copied
with the code block content.
Default:true
Whether a "copy to clipboard" button should be shown.
Default:false
Whether a label with the current language's display name should be shown.
Whether to show buttons for collapsing/expanding code blocks.
Currently only available for JSON code blocks.
Defaults to true when the language is json.
Default:false
Whether line numbers should be shown in the left gutter.