markdown-features.mdx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. ---
  2. sidebar_position: 4
  3. ---
  4. # Markdown Features
  5. Docusaurus supports **[Markdown](https://daringfireball.net/projects/markdown/syntax)** and a few **additional features**.
  6. ## Front Matter
  7. Markdown documents have metadata at the top called [Front Matter](https://jekyllrb.com/docs/front-matter/):
  8. ```text title="my-doc.md"
  9. // highlight-start
  10. ---
  11. id: my-doc-id
  12. title: My document title
  13. description: My document description
  14. slug: /my-custom-url
  15. ---
  16. // highlight-end
  17. Markdown content
  18. ```
  19. ## Headings {/* #my-heading-id */}
  20. Markdown headings are supported using the standard “#” syntax and are automatically added to the table of contents. The number of `#` corresponds to the heading level.
  21. ```md
  22. ## Headings
  23. My text
  24. ```
  25. ### Heading Ids {/* #my-custom-id */}
  26. Add `{/* #my-custom-id */}` after the heading text to assign it an explicit anchor id, used for linking.
  27. ```md
  28. ### Heading Ids {/_ #my-custom-id _/}
  29. ```
  30. ## Links
  31. Regular Markdown links are supported, using url paths or relative file paths.
  32. ```md
  33. Let's see how to [Create a page](/create-a-page).
  34. ```
  35. ```md
  36. Let's see how to [Create a page](./create-a-page.mdx).
  37. ```
  38. **Result:** Let's see how to [Create a page](./create-a-page.mdx).
  39. ## Images
  40. Regular Markdown images are supported.
  41. You can use absolute paths to reference images in the static directory (`static/img/docusaurus.png`):
  42. ```md
  43. ![Docusaurus logo](/img/docusaurus.png)
  44. ```
  45. ![Docusaurus logo](/img/docusaurus.png)
  46. You can reference images relative to the current file as well. This is particularly useful to colocate images close to the Markdown files using them:
  47. ```md
  48. ![Docusaurus logo](./img/docusaurus.png)
  49. ```
  50. ## Code Blocks
  51. Markdown code blocks are supported with Syntax highlighting.
  52. ````md
  53. ```jsx title="src/components/HelloDocusaurus.js"
  54. function HelloDocusaurus() {
  55. return <h1>Hello, Docusaurus!</h1>;
  56. }
  57. ```
  58. ````
  59. ```jsx title="src/components/HelloDocusaurus.js"
  60. function HelloDocusaurus() {
  61. return <h1>Hello, Docusaurus!</h1>;
  62. }
  63. ```
  64. ## Admonitions
  65. Docusaurus has a special syntax to create admonitions and callouts:
  66. ```md
  67. :::tip[My tip]
  68. Use this awesome feature option
  69. :::
  70. :::danger[Take care]
  71. This action is dangerous
  72. :::
  73. ```
  74. :::tip[My tip]
  75. Use this awesome feature option
  76. :::
  77. :::danger[Take care]
  78. This action is dangerous
  79. :::
  80. ## MDX and React Components
  81. [MDX](https://mdxjs.com/) can make your documentation more **interactive** and allows using any **React components inside Markdown**:
  82. ```jsx
  83. export const Highlight = ({children, color}) => (
  84. <span
  85. style={{
  86. backgroundColor: color,
  87. borderRadius: '20px',
  88. color: '#fff',
  89. padding: '10px',
  90. cursor: 'pointer',
  91. }}
  92. onClick={() => {
  93. alert(`You clicked the color ${color} with label ${children}`)
  94. }}>
  95. {children}
  96. </span>
  97. );
  98. This is <Highlight color="#25c2a0">Docusaurus green</Highlight> !
  99. This is <Highlight color="#1877F2">Facebook blue</Highlight> !
  100. ```
  101. export const Highlight = ({children, color}) => (
  102. <span
  103. style={{
  104. backgroundColor: color,
  105. borderRadius: '20px',
  106. color: '#fff',
  107. padding: '10px',
  108. cursor: 'pointer',
  109. }}
  110. onClick={() => {
  111. alert(`You clicked the color ${color} with label ${children}`);
  112. }}>
  113. {children}
  114. </span>
  115. );
  116. This is <Highlight color="#25c2a0">Docusaurus green</Highlight> !
  117. This is <Highlight color="#1877F2">Facebook blue</Highlight> !