Prism code highlight
Installation
Package depends on react, react-dom, @mantine/hooks, @mantine/core and prism-react-renderer.
Install with npm:
Install with yarn:
Usage
Use Prism component to highlight code with Mantine theme styles. Component uses prism-react-renderer under the hood and support light and dark theme, it is used in Mantine docs to display all code examples.
Line numbers
Set withLineNumbers
prop to display line numbers:
Lines highlight
To highlight individual lines use highlightLines
prop with object containing
line numbers as keys and highlight options as values. Highlight options include
color from theme.colors
and label which replaces line number:
Copy button
To remove copy button set noCopy
prop.
Copy button labels can be changed with copyLabel
and copiedLabel
props:
Native scrollbars
By default, Prism uses ScrollArea component to handle overflow content,
to replace it with native scrollbars set scrollAreaComponent="div"
:
<p>Long code that will force Prism to have a horizontal scrollbar, by default, scroll behavior is handled by ScrollArea component, but it can be changed to native browser scrollbars</p>
With tabs
To display multiple files use Prism.Tabs
component, it supports the same props as Tabs component:
Force dark/light theme
You can force dark/light color scheme by setting colorScheme
prop:
Languages
Component supports all languages which are supported by prism-react-renderer: