API reference

CodeBlock

Top-level root component which contains all the sub-components to construct a code block.

PropTypeDefaultDescription
codestring–Code to be rendered.
languagestring–Language to use for syntax highlighting.
lines(number | string)[][]Lines / Line ranges to highlight.
wordsstring[][]Words to highlight.
themePrismThemethemes.vsDarkTheme to use for syntax highlighting.

All other prism-react-render props (opens in a new tab) can also be passed to this component.


CodeBlock.Code

Container which contains code to render each line of the code.

PropTypeDefaultDescription
asString | ComponentpreThe element or component it should render as.
childrenReactNode | RenderProp–How each line of the code should be rendered.
Render PropTypeDescription
isLineHighlightedbooleanWhether the current line is highlighted or not based on what is passed to the lines prop.
lineNumbernumberLine number of the current line.

CodeBlock.LineContent

Container for a single line of the code.

PropTypeDefaultDescription
asString | ComponentcodeThe element or component it should render as.
childrenReactNode–What should the current line contain.

CodeBlock.Token

Renders a syntax-highlighted token from the current line.

PropTypeDefaultDescription
asString | ComponentspanThe element or component it should render as.
childrenReactNode | RenderProp–How a token should be rendered.
Render PropTypeDescription
isTokenHighlightedbooleanWhether the current token is highlighted or not based on what is passed to the words prop.
childrenstringContent of the current token.

CodeBlock.LineNumber

Renders the line number for the current line.

PropTypeDefaultDescription
asString | ComponentspanThe element or component it should render as.