CodeHighlight
Highlight code with shiki or highlight.js
Source
LLM docs
Docs
Package
License
Example
CodeHighlight component is used to display code snippets with syntax highlighting.
It can be used with any code highlighting library with adapters.
Example of code highlighting with shiki:
Copy button
You can customize copy button labels with copyLabel and copiedLabel props.
In case you need to remove the copy button, set withCopyButton={false}.
With tabs
CodeHighlightTabs component allows you to organize multiple code blocks into tabs:
Tabs with icons
You can use any React node as tab icon. The example below uses TypeScript and CSS
icons from the @mantinex/dev-icons package, but you can use any other icons library or custom
icons:
Tabs icons based on file name
As an alternative to providing icons manually for each tab, you can use the getFileIcon prop
to assign icons based on file name. getFileIcon accepts a file name and must return a React node
or null.
Line numbers
Set withLineNumbers prop to display line numbers alongside the code:
First line indentation
CodeHighlight trims the code before rendering it, so the indentation of the first line
is removed. Set withFirstLineIndentation prop to preserve it:
Default: the first line is dedented
withFirstLineIndentation
Expandable code
If the code snippet is too long, you can make it expandable with withExpandButton
and defaultExpanded={false} props. To change the label of the expand/collapse control
tooltip, use expandCodeLabel and collapseCodeLabel.
Custom controls
Use the controls prop with the CodeHighlightControl component to add custom controls
to the code block:
Inline code
InlineCodeHighlight component allows you to highlight inline code snippets:
You can highlight code inline: <InlineCodeHighlight code="" language="tsx" />. Is that not cool?