| 
 | 1 | +# Markdown & MDX  | 
 | 2 | + | 
 | 3 | +Rspress supports not only Markdown but also [MDX](https://mdxjs.com/), a powerful way to develop content.  | 
 | 4 | + | 
 | 5 | +## Markdown  | 
 | 6 | + | 
 | 7 | +MDX is a superset of Markdown, which means you can write Markdown files as usual. For example:  | 
 | 8 | + | 
 | 9 | +```md  | 
 | 10 | +# Hello world  | 
 | 11 | +```  | 
 | 12 | + | 
 | 13 | +## Use component  | 
 | 14 | + | 
 | 15 | +When you want to use React components in Markdown files, you should name your files with `.mdx` extension. For example:  | 
 | 16 | + | 
 | 17 | +```mdx  | 
 | 18 | +// docs/index.mdx  | 
 | 19 | +import { CustomComponent } from './custom';  | 
 | 20 | + | 
 | 21 | +# Hello world  | 
 | 22 | + | 
 | 23 | +<CustomComponent />  | 
 | 24 | +```  | 
 | 25 | + | 
 | 26 | +## Front matter  | 
 | 27 | + | 
 | 28 | +You can add Front Matter at the beginning of your Markdown file, which is a YAML-formatted object that defines some metadata. For example:  | 
 | 29 | + | 
 | 30 | +```yaml  | 
 | 31 | +---  | 
 | 32 | +title: Hello world  | 
 | 33 | +---  | 
 | 34 | +```  | 
 | 35 | + | 
 | 36 | +> Note: By default, Rspress uses h1 headings as html headings.  | 
 | 37 | +
  | 
 | 38 | +You can also access properties defined in Front Matter in the body, for example:  | 
 | 39 | + | 
 | 40 | +```markdown  | 
 | 41 | +---  | 
 | 42 | +title: Hello world  | 
 | 43 | +---  | 
 | 44 | + | 
 | 45 | +# {frontmatter.title}  | 
 | 46 | +```  | 
 | 47 | + | 
 | 48 | +The previously defined properties will be passed to the component as `frontmatter` properties. So the final output will be:  | 
 | 49 | + | 
 | 50 | +```html  | 
 | 51 | +<h1>Hello world</h1>  | 
 | 52 | +```  | 
 | 53 | + | 
 | 54 | +## Custom container  | 
 | 55 | + | 
 | 56 | +You can use the `:::` syntax to create custom containers and support custom titles. For example:  | 
 | 57 | + | 
 | 58 | +**Input:**  | 
 | 59 | + | 
 | 60 | +```markdown  | 
 | 61 | +:::tip  | 
 | 62 | +This is a `block` of type `tip`  | 
 | 63 | +:::  | 
 | 64 | + | 
 | 65 | +:::info  | 
 | 66 | +This is a `block` of type `info`  | 
 | 67 | +:::  | 
 | 68 | + | 
 | 69 | +:::warning  | 
 | 70 | +This is a `block` of type `warning`  | 
 | 71 | +:::  | 
 | 72 | + | 
 | 73 | +:::danger  | 
 | 74 | +This is a `block` of type `danger`  | 
 | 75 | +:::  | 
 | 76 | + | 
 | 77 | +::: details  | 
 | 78 | +This is a `block` of type `details`  | 
 | 79 | +:::  | 
 | 80 | + | 
 | 81 | +:::tip Custom Title  | 
 | 82 | +This is a `block` of `Custom Title`  | 
 | 83 | +:::  | 
 | 84 | + | 
 | 85 | +:::tip{title="Custom Title"}  | 
 | 86 | +This is a `block` of `Custom Title`  | 
 | 87 | +:::  | 
 | 88 | +```  | 
 | 89 | + | 
 | 90 | +**Output:**  | 
 | 91 | + | 
 | 92 | +:::tip  | 
 | 93 | +This is a `block` of type `tip`  | 
 | 94 | +:::  | 
 | 95 | + | 
 | 96 | +:::info  | 
 | 97 | +This is a `block` of type `info`  | 
 | 98 | +:::  | 
 | 99 | + | 
 | 100 | +:::warning  | 
 | 101 | +This is a `block` of type `warning`  | 
 | 102 | +:::  | 
 | 103 | + | 
 | 104 | +:::danger  | 
 | 105 | +This is a `block` of type `danger`  | 
 | 106 | +:::  | 
 | 107 | + | 
 | 108 | +::: details  | 
 | 109 | +This is a `block` of type `details`  | 
 | 110 | +:::  | 
 | 111 | + | 
 | 112 | +:::tip Custom Title  | 
 | 113 | +This is a `block` of `Custom Title`  | 
 | 114 | +:::  | 
 | 115 | + | 
 | 116 | +:::tip{title="Custom Title"}  | 
 | 117 | +This is a `block` of `Custom Title`  | 
 | 118 | +:::  | 
 | 119 | + | 
 | 120 | +## Code block  | 
 | 121 | + | 
 | 122 | +### Basic usage  | 
 | 123 | + | 
 | 124 | +You can use the \`\`\` syntax to create code blocks and support custom titles. For example:  | 
 | 125 | + | 
 | 126 | +**Input:**  | 
 | 127 | + | 
 | 128 | +````md  | 
 | 129 | +```js  | 
 | 130 | +console.log('Hello World');  | 
 | 131 | +```  | 
 | 132 | + | 
 | 133 | +```js title="hello.js"  | 
 | 134 | +console.log('Hello World');  | 
 | 135 | +```  | 
 | 136 | +````  | 
 | 137 | + | 
 | 138 | +**Output:**  | 
 | 139 | + | 
 | 140 | +```js  | 
 | 141 | +console.log('Hello World');  | 
 | 142 | +```  | 
 | 143 | + | 
 | 144 | +```js title="hello.js"  | 
 | 145 | +console.log('Hello World');  | 
 | 146 | +```  | 
 | 147 | + | 
 | 148 | +### Show line numbers  | 
 | 149 | + | 
 | 150 | +If you want to display line numbers, you can enable the `showLineNumbers` option in the config file:  | 
 | 151 | + | 
 | 152 | +```ts title="rspress.config.ts"  | 
 | 153 | +export default {  | 
 | 154 | +  // ...  | 
 | 155 | +  markdown: {  | 
 | 156 | +    showLineNumbers: true,  | 
 | 157 | +  },  | 
 | 158 | +};  | 
 | 159 | +```  | 
 | 160 | + | 
 | 161 | +### Wrap code  | 
 | 162 | + | 
 | 163 | +If you want to wrap long code line by default, you can enable the `defaultWrapCode` option in the config file:  | 
 | 164 | + | 
 | 165 | +```ts title="rspress.config.ts"  | 
 | 166 | +export default {  | 
 | 167 | +  // ...  | 
 | 168 | +  markdown: {  | 
 | 169 | +    defaultWrapCode: true,  | 
 | 170 | +  },  | 
 | 171 | +};  | 
 | 172 | +```  | 
 | 173 | + | 
 | 174 | +### Line highlighting  | 
 | 175 | + | 
 | 176 | +You can also apply line highlighting and code block title at the same time, for example:  | 
 | 177 | + | 
 | 178 | +**Input:**  | 
 | 179 | + | 
 | 180 | +````md  | 
 | 181 | +```js title="hello.js" {1,3-5}  | 
 | 182 | +console.log('Hello World');  | 
 | 183 | + | 
 | 184 | +const a = 1;  | 
 | 185 | + | 
 | 186 | +console.log(a);  | 
 | 187 | + | 
 | 188 | +const b = 2;  | 
 | 189 | + | 
 | 190 | +console.log(b);  | 
 | 191 | +```  | 
 | 192 | +````  | 
 | 193 | + | 
 | 194 | +**Output:**  | 
 | 195 | + | 
 | 196 | +```js title="hello.js" {1,3-5}  | 
 | 197 | +console.log('Hello World');  | 
 | 198 | + | 
 | 199 | +const a = 1;  | 
 | 200 | + | 
 | 201 | +console.log(a);  | 
 | 202 | + | 
 | 203 | +const b = 2;  | 
 | 204 | + | 
 | 205 | +console.log(b);  | 
 | 206 | +```  | 
 | 207 | + | 
 | 208 | +## Rustify MDX compiler  | 
 | 209 | + | 
 | 210 | +You can enable Rustify MDX compiler by following config:  | 
0 commit comments