MDX and React components
Rspress supports MDX, a content authoring format that seamlessly combines Markdown with JSX. MDX allows you to use React components directly in your documentation, combining Markdown's concise syntax with the power of the React ecosystem, making it ideal for building interactive, component-based technical documentation.
What is MDX
MDX is a combination of Markdown and JSX syntax, allowing you to write and use React components directly in Markdown documents.
We recommend using .mdx for all documentation files, which enables you to write content just like regular Markdown and also import and utilize the built-in components provided by Rspress.
Componentization
In MDX, every .mdx file is compiled into a React component, which means it can be imported like any component and can freely render React components. For example:
It will be rendered as:
Testing the use of MDX fragments and React components.
This is mdx fragment.
This is a component from tsx
You can use built-in components provided by Rspress or install some React component libraries to enrich your documentation in .mdx files.
Routing convention
In the docs directory, MDX fragments or React components need to be excluded from routing through the route.exclude configuration. For convenience, files starting with "_" are excluded by default via route.excludeConvention.
You can also place components in adjacent directories outside the docs directory, for example:
It will be rendered as:
button
This is text from MDX
Escape Hatch: writing document content in tsx
It will be rendered as:
This is content in tsx, but the styles are the same as in the documentation, such as @rspress/core. However, this text with className="rp-not-doc"@rspress/core will not take effect
tsx and html syntax can make it difficult to extract static information, such as local search indexes.
It is more recommended to use .mdx files to write document content and use .tsx files to write interactive dynamic content.