Line Numbers

How to enable line numbers in code blocks using Prismjs.

PrismjsReactMarkdownMDX

Preview

Preparing…

Usage

Component

Add the lineNumbers prop to the CodeBlockPrismjs component:

<CodeBlockPrismjs lineNumbers={true} language="tsx" code={code} />

Markdown/MDX

Add prismjs-line-numbers class to the PrePrismComponent:

<CodeBlockContent>
  <pre className="prism-pre prism-line-numbers">
    <code dangerouslySetInnerHTML={{ __html: codeHTML }} />
  </pre>
</CodeBlockContent>