Highlighter
Syntax-highlighted code block with copy button
import Highlighter from "@intility/bifrost-react-highlighter";A syntax-highlighted code block with a Bifrost-styled header, copy button, and
line-number gutter. Built on
react-syntax-highlighter
(Prism) and themed via Bifrost CSS variables so it follows the active color
mode.
Install package
- Run the following command to install:
npm install @intility/bifrost-react-highlighter- Include
highlighter.cssglobally:
import "@intility/bifrost-react-highlighter/highlighter.css";- Import the component:
import Highlighter from "@intility/bifrost-react-highlighter";Basic usage
Pass the source code as a string child and provide a Prism language identifier
via the language prop.
<Highlighter language="typescript">{codeString}</Highlighter>Language
Any Prism-supported language identifier works.
<Highlighter language="css">{cssCode}</Highlighter>
<Highlighter language="bash">{bashCode}</Highlighter>Line numbers
Line numbers are shown by default. Use noLineNumbers to disable them.
<Highlighter language="javascript" noLineNumbers>
{code}
</Highlighter>Header
The header shows the language label by default. Pass header to override it
with a custom title — useful for showing a filename or other context.
<Highlighter language="typescript" header="greet.ts">
{code}
</Highlighter>Use noHeader to remove the entire header (both the title and the copy
button).
<Highlighter language="css" noHeader>
{code}
</Highlighter>Use noCopy to hide the copy button only.
<Highlighter language="typescript" noCopy>
{code}
</Highlighter>Line wrapping
By default long lines scroll horizontally. Use wrapLines to soft-wrap them
to the container width instead.
<Highlighter language="typescript" wrapLines>
{code}
</Highlighter>Sandbox
import { useState } from "react"; import Highlighter from "@intility/bifrost-react-highlighter"; import "@intility/bifrost-react-highlighter/highlighter.css"; const code = `const greet = (name: string) => { return \`Hello, \${name}!\`; }; console.log(greet("world"));`; export default function HighlighterDemo() { return <Highlighter language="typescript">{code}</Highlighter>; }