Rspress supports MDX, a powerful way to develop content.
MDX is a superset of Markdown, which means you can write Markdown files as usual. For example:
# Hello World
When you want to use React components in Markdown files, you should name your files with .mdx
extension. For example:
// docs/index.mdx
import { CustomComponent } from './custom';
# Hello World
<CustomComponent />
You can add Front Matter at the beginning of your Markdown file, which is a YAML-formatted object that defines some metadata. For example:
---
title: Hello World
---
Note: By default, Rspress uses h1 headings as html headings.
You can also access properties defined in Front Matter in the body, for example:
---
title: Hello World
---
# {frontmatter.title}
The previously defined properties will be passed to the component as frontmatter
properties. So the final output will be:
<h1>Hello World</h1>
You can use the :::
syntax to create custom containers and support custom titles. For example:
Input:
:::tip
This is a `block` of type `tip`
:::
:::info
This is a `block` of type `info`
:::
:::warning
This is a `block` of type `warning`
:::
:::danger
This is a `block` of type `danger`
:::
::: details
This is a `block` of type `details`
:::
:::tip Custom Title
This is a `block` of `Custom Title`
:::
:::tip{title="Custom Title"}
This is a `block` of `Custom Title`
:::
Output:
This is a block
of type tip
This is a block
of type info
This is a block
of type warning
This is a block
of type danger
This is a block
of type details
This is a block
of Custom Title
This is a block
of Custom Title
You can use the ``` syntax to create code blocks and support custom titles. For example:
Input:
```js
console.log('Hello World');
```
```js title="hello.js"
console.log('Hello World');
```
Output:
console.log('Hello World');
console.log('Hello World');
If you want to display line numbers, you can enable the showLineNumbers
option in the config file:
export default {
// ...
markdown: {
showLineNumbers: true,
},
};
You can also apply line highlighting and code block title at the same time, for example:
Input:
```js title="hello.js" {1,3-5}
console.log('Hello World');
const a = 1;
console.log(a);
const b = 2;
console.log(b);
```
Ouput:
1console.log('Hello World');
2
3const a = 1;
4
5console.log(a);
6
7const b = 2;
8
9console.log(b);
You can enable Rustify MDX compiler by following config:
import { defineConfig } from 'rspress/config';
export default defineConfig({
markdown: {
experimentalMdxRs: true,
},
});
The bottom layer of this function is based on the @modern/mdx-rs-binding library developed by Rspress. The performance is 5 ~ 10 times higher than the JS version of the MDX compiler, but the JS version of the plugin is not yet supported. If you need to add a custom remark or rehype plugin, it is not recommended to enable this function.