Fern uses Shiki for syntax highlighting in code blocks. It’s reliable and performant. Below are examples of how you can configure syntax highlighting in code snippets.
To create a code snippet, you need to wrap your code in three backticks. You can also specify the language for syntax highlighting after the opening backticks.
You can add a title to your code snippet by adding a title after the language identifier.
You can highlight specific lines in your code snippet by placing a numeric range inside {}
after the language identifier.
Instead of highlighting lines, you can focus on specific lines by adding a comment [!code focus] or by adding a
focus attribute after the language identifier. The focus attribute works the same way as the highlight attribute.
You can control the max height of the code block by adding
a maxLines attribute after the language identifier. The
maxLines attribute should be a number representing the maximum
number of lines to display. By default, the code block will display up to 20 lines.
By default, long lines that exceed the width of the code block become scrollable:
To disable scrolling and wrap overflow onto the next line, use the wordWrap prop:
You can combine the title, highlight, focus, maxLines, and wordWrap
props to create a code block with a title, highlighted lines,
and a maximum height.
The CodeBlocks component allows you to display multiple code blocks in a tabbed interface.
Multiple CodeBlocks on a page automatically synchronize, showing the same language across all blocks.
You can override the synchronization of code blocks by setting the for prop.
Option A
Option B