|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- # Markdown & MDX
-
- Rspress supports not only Markdown but also [MDX](https://mdxjs.com/), a powerful way to develop content.
-
- ## Markdown
-
- MDX is a superset of Markdown, which means you can write Markdown files as usual. For example:
-
- ```md
- # Hello world
- ```
-
- ## Use component
-
- When you want to use React components in Markdown files, you should name your files with `.mdx` extension. For example:
-
- ```mdx
- // docs/index.mdx
- import { CustomComponent } from './custom';
-
- # Hello world
-
- <CustomComponent />
- ```
-
- ## Front matter
-
- You can add Front Matter at the beginning of your Markdown file, which is a YAML-formatted object that defines some metadata. For example:
-
- ```yaml
- ---
- 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:
-
- ```markdown
- ---
- title: Hello world
- ---
-
- # {frontmatter.title}
- ```
-
- The previously defined properties will be passed to the component as `frontmatter` properties. So the final output will be:
-
- ```html
- <h1>Hello world</h1>
- ```
-
- ## Custom container
-
- You can use the `:::` syntax to create custom containers and support custom titles. For example:
-
- **Input:**
-
- ```markdown
- :::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:**
-
- :::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`
- :::
-
- ## Code block
-
- ### Basic usage
-
- You can use the \`\`\` syntax to create code blocks and support custom titles. For example:
-
- **Input:**
-
- ````md
- ```js
- console.log('Hello World');
- ```
-
- ```js title="hello.js"
- console.log('Hello World');
- ```
- ````
-
- **Output:**
-
- ```js
- console.log('Hello World');
- ```
-
- ```js title="hello.js"
- console.log('Hello World');
- ```
-
- ### Show line numbers
-
- If you want to display line numbers, you can enable the `showLineNumbers` option in the config file:
-
- ```ts title="rspress.config.ts"
- export default {
- // ...
- markdown: {
- showLineNumbers: true,
- },
- };
- ```
-
- ### Wrap code
-
- If you want to wrap long code line by default, you can enable the `defaultWrapCode` option in the config file:
-
- ```ts title="rspress.config.ts"
- export default {
- // ...
- markdown: {
- defaultWrapCode: true,
- },
- };
- ```
-
- ### Line highlighting
-
- You can also apply line highlighting and code block title at the same time, for example:
-
- **Input:**
-
- ````md
- ```js title="hello.js" {1,3-5}
- console.log('Hello World');
-
- const a = 1;
-
- console.log(a);
-
- const b = 2;
-
- console.log(b);
- ```
- ````
-
- **Output:**
-
- ```js title="hello.js" {1,3-5}
- console.log('Hello World');
-
- const a = 1;
-
- console.log(a);
-
- const b = 2;
-
- console.log(b);
- ```
-
- ## Rustify MDX compiler
-
- You can enable Rustify MDX compiler by following config:
|