Integrated Shiki code highlighting plugin. By default, Rspress uses Prism.js to achieve syntax highlighting. However, in some cases, when you need to implement code highlighting for more languages, Prism.js may not be sufficient, so you can integrate this plugin to use Shiki to support more languages.
However, after introducing the Shiki plugin, the compilation performance of Rspress will decrease, so please evaluate whether you need to introduce this plugin based on your needs.
First, write the following configuration in the configuration file:
This plugin supports passing in an object configuration. The properties of this object configuration are as follows:
The code highlighting theme uses css-variables
. You can also choose your favorite theme, refer to the Shiki theme list documentation for details.
The default languages supported include js
, jsx
, ts
, tsx
, json
, css
, scss
, less
, xml
, diff
, yaml
, md
, mdx
, bash
. If you want to support more languages, you can pass the langs
attribute in the configuration file. This attribute is an array, each item in the array is an id of a language, refer to the Shiki-supported language list for details.
Transformer is a concept in this plugin, its function is to transform specific syntax of code blocks, for example, you can use this feature to implement the diff highlighting effect of code blocks.
A few Transformers are built into this plugin, including:
createTransformerDiff
: Implementation of the diff highlighting effect of the code block.createTransformerLineNumber
: Implement the display of the line number of the code block.createTransformerErrorLevel
: Implement the display of the error level of the corresponding line of the code block, including error
and warning
.createTransformerHighlight
: Implement line highlighting display of the code block.createTransformerFocus
: Implement line focus display of the code block.You can enable these Transformers by configuring the transformers
attribute, such as:
Then let us introduce how to use the syntax corresponding to these Transformers.
Use the diff
syntax in the markdown code block, such as:
This will automatically apply the diff highlighting effect to the corresponding line of code.
Use the hl
syntax in the markdown code block, such as:
This will automatically display the line number for the corresponding line of code.
Use the error
or warning
syntax in the markdown code block, such as:
This will automatically display the error level for the corresponding line of code.
Use the focus
syntax in the markdown code block, such as:
This will automatically display the focus effect for the corresponding line of code.