| Jeroen van Meeuwen | e939c28 | 2024-06-11 11:53:26 +0200 | [diff] [blame^] | 1 | --- |
| 2 | sidebar_position: 4 |
| 3 | --- |
| 4 | |
| 5 | # Markdown Features |
| 6 | |
| 7 | Docusaurus supports **[Markdown](https://daringfireball.net/projects/markdown/syntax)** and a few **additional features**. |
| 8 | |
| 9 | ## Front Matter |
| 10 | |
| 11 | Markdown documents have metadata at the top called [Front Matter](https://jekyllrb.com/docs/front-matter/): |
| 12 | |
| 13 | ```text title="my-doc.md" |
| 14 | // highlight-start |
| 15 | --- |
| 16 | id: my-doc-id |
| 17 | title: My document title |
| 18 | description: My document description |
| 19 | slug: /my-custom-url |
| 20 | --- |
| 21 | // highlight-end |
| 22 | |
| 23 | ## Markdown heading |
| 24 | |
| 25 | Markdown text with [links](./hello.md) |
| 26 | ``` |
| 27 | |
| 28 | ## Links |
| 29 | |
| 30 | Regular Markdown links are supported, using url paths or relative file paths. |
| 31 | |
| 32 | ```md |
| 33 | Let's see how to [Create a page](/create-a-page). |
| 34 | ``` |
| 35 | |
| 36 | ```md |
| 37 | Let's see how to [Create a page](./create-a-page.md). |
| 38 | ``` |
| 39 | |
| 40 | **Result:** Let's see how to [Create a page](./create-a-page.md). |
| 41 | |
| 42 | ## Images |
| 43 | |
| 44 | Regular Markdown images are supported. |
| 45 | |
| 46 | You can use absolute paths to reference images in the static directory (`static/img/docusaurus.png`): |
| 47 | |
| 48 | ```md |
| 49 |  |
| 50 | ``` |
| 51 | |
| 52 |  |
| 53 | |
| 54 | 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: |
| 55 | |
| 56 | ```md |
| 57 |  |
| 58 | ``` |
| 59 | |
| 60 | ## Code Blocks |
| 61 | |
| 62 | Markdown code blocks are supported with Syntax highlighting. |
| 63 | |
| 64 | ````md |
| 65 | ```jsx title="src/components/HelloDocusaurus.js" |
| 66 | function HelloDocusaurus() { |
| 67 | return <h1>Hello, Docusaurus!</h1>; |
| 68 | } |
| 69 | ``` |
| 70 | ```` |
| 71 | |
| 72 | ```jsx title="src/components/HelloDocusaurus.js" |
| 73 | function HelloDocusaurus() { |
| 74 | return <h1>Hello, Docusaurus!</h1>; |
| 75 | } |
| 76 | ``` |
| 77 | |
| 78 | ## Admonitions |
| 79 | |
| 80 | Docusaurus has a special syntax to create admonitions and callouts: |
| 81 | |
| 82 | ```md |
| 83 | :::tip My tip |
| 84 | |
| 85 | Use this awesome feature option |
| 86 | |
| 87 | ::: |
| 88 | |
| 89 | :::danger Take care |
| 90 | |
| 91 | This action is dangerous |
| 92 | |
| 93 | ::: |
| 94 | ``` |
| 95 | |
| 96 | :::tip My tip |
| 97 | |
| 98 | Use this awesome feature option |
| 99 | |
| 100 | ::: |
| 101 | |
| 102 | :::danger Take care |
| 103 | |
| 104 | This action is dangerous |
| 105 | |
| 106 | ::: |
| 107 | |
| 108 | ## MDX and React Components |
| 109 | |
| 110 | [MDX](https://mdxjs.com/) can make your documentation more **interactive** and allows using any **React components inside Markdown**: |
| 111 | |
| 112 | ```jsx |
| 113 | export const Highlight = ({children, color}) => ( |
| 114 | <span |
| 115 | style={{ |
| 116 | backgroundColor: color, |
| 117 | borderRadius: '20px', |
| 118 | color: '#fff', |
| 119 | padding: '10px', |
| 120 | cursor: 'pointer', |
| 121 | }} |
| 122 | onClick={() => { |
| 123 | alert(`You clicked the color ${color} with label ${children}`) |
| 124 | }}> |
| 125 | {children} |
| 126 | </span> |
| 127 | ); |
| 128 | |
| 129 | This is <Highlight color="#25c2a0">Docusaurus green</Highlight> ! |
| 130 | |
| 131 | This is <Highlight color="#1877F2">Facebook blue</Highlight> ! |
| 132 | ``` |
| 133 | |
| 134 | export const Highlight = ({children, color}) => ( |
| 135 | <span |
| 136 | style={{ |
| 137 | backgroundColor: color, |
| 138 | borderRadius: '20px', |
| 139 | color: '#fff', |
| 140 | padding: '10px', |
| 141 | cursor: 'pointer', |
| 142 | }} |
| 143 | onClick={() => { |
| 144 | alert(`You clicked the color ${color} with label ${children}`); |
| 145 | }}> |
| 146 | {children} |
| 147 | </span> |
| 148 | ); |
| 149 | |
| 150 | This is <Highlight color="#25c2a0">Docusaurus green</Highlight> ! |
| 151 | |
| 152 | This is <Highlight color="#1877F2">Facebook blue</Highlight> ! |