In the documentation
Code blocks
Code blocks are a way to display code in a readable format.
Explainer implements Shiki
for syntax highlighting, you can read the Shiki documentation for more information on how to customize the syntax highlighting.
Highlighting
Highlighting can be done before or after the declaration with the [!code highlight]
syntax.
Single line
Single highlight can be done with the [!code highlight]
syntax.
pub struct User {
pub firstname: String,
pub lastname: String,
}
pub struct User {
pub firstname: String,
pub lastname: String,
}
Multiple lines
Multiple highlights can be done with the [!code highlight:1,2]
syntax.
pub struct User {
pub firstname: String,
pub lastname: String,
}
Code block with focused line
The [!code focus:<n>]
syntax will highlight the line 2 of the code block.
pub struct User {
pub firstname: String,
pub lastname: String,
}
Code block with status
The [!code error]
and [!code warning]
syntax will highlight the line with the error or warning status.
Code block with error
Error status can be done with the [!code error]
syntax.
pub struct User {
pub firstname: String
pub lastname: String,
}
Code block with warning
Warning status can be done with the [!code warning]
syntax.
pub struct User {
pub firstname: String,
pub lastname: String,
}
Line modifiers
The [!code --]
and [!code ++]
syntax will remove or add a line to the code block.
pub struct User {
pub firstname: String,
pub lastname: String,
}
impl User {
pub fn new() -> Self {
pub fn new(firstname: String, lastname: String) -> Self {
Self { firstname, lastname }
}
}
Group code blocks
Group code blocks can be done with the :::code-group labels=[...labels]
syntax.
Only code blocks can be used in a group.
:::code-group auto
// Code block without labels
:::
pub struct User {
pub firstname: String,
pub lastname: String,
}