You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.md 3.3 kB

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

Dora中文社区官网

Contributors (1)