Skip to main content
/
/
/
Highlighter

Highlighter

Syntax-highlighted code block with copy button

ReactCSS
import Highlighter from "@intility/bifrost-react-highlighter";
Props

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

  1. Run the following command to install:
Shell
npm install @intility/bifrost-react-highlighter
  1. Include highlighter.css globally:
TypeScript
import "@intility/bifrost-react-highlighter/highlighter.css";
  1. Import the component:
TypeScript
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.

TSX
<Highlighter language="typescript">{codeString}</Highlighter>

Language

Any Prism-supported language identifier works.

TSX
<Highlighter language="css">{cssCode}</Highlighter>
<Highlighter language="bash">{bashCode}</Highlighter>

Line numbers

Line numbers are shown by default. Use noLineNumbers to disable them.

TSX
<Highlighter language="javascript" noLineNumbers>
  {code}
</Highlighter>

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.

TSX
<Highlighter language="typescript" header="greet.ts">
  {code}
</Highlighter>

Use noHeader to remove the entire header (both the title and the copy button).

TSX
<Highlighter language="css" noHeader>
  {code}
</Highlighter>
.button {
  color: var(--bfc-base-c);
  padding: 0.5rem 1rem;
}

Use noCopy to hide the copy button only.

TSX
<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.

TSX
<Highlighter language="typescript" wrapLines>
  {code}
</Highlighter>
TypeScript
const message = "This is a really long string that will overflow horizontally on narrow screens unless line wrapping is enabled.";