| 1 |
# Markdown |
| 2 |
|
| 3 |
mdBook's [parser](https://github.com/raphlinus/pulldown-cmark) adheres to the [CommonMark](https://commonmark.org/) specification with some extensions described below. |
| 4 |
You can take a quick [tutorial](https://commonmark.org/help/tutorial/), |
| 5 |
or [try out](https://spec.commonmark.org/dingus/) CommonMark in real time. A complete Markdown overview is out of scope for |
| 6 |
this documentation, but below is a high level overview of some of the basics. For a more in-depth experience, check out the |
| 7 |
[Markdown Guide](https://www.markdownguide.org). |
| 8 |
|
| 9 |
## Text and paragraphs |
| 10 |
|
| 11 |
Text is rendered relatively predictably: |
| 12 |
|
| 13 |
```markdown |
| 14 |
Here is a line of text. |
| 15 |
|
| 16 |
This is a new line. |
| 17 |
``` |
| 18 |
|
| 19 |
Will look like you might expect: |
| 20 |
|
| 21 |
Here is a line of text. |
| 22 |
|
| 23 |
This is a new line. |
| 24 |
|
| 25 |
## Headings |
| 26 |
|
| 27 |
Headings use the `#` marker and should be on a line by themselves. More `#` mean smaller headings: |
| 28 |
|
| 29 |
```markdown |
| 30 |
### A heading |
| 31 |
|
| 32 |
Some text. |
| 33 |
|
| 34 |
#### A smaller heading |
| 35 |
|
| 36 |
More text. |
| 37 |
``` |
| 38 |
|
| 39 |
### A heading |
| 40 |
|
| 41 |
Some text. |
| 42 |
|
| 43 |
#### A smaller heading |
| 44 |
|
| 45 |
More text. |
| 46 |
|
| 47 |
## Lists |
| 48 |
|
| 49 |
Lists can be unordered or ordered. Ordered lists will order automatically: |
| 50 |
|
| 51 |
```markdown |
| 52 |
* milk |
| 53 |
* eggs |
| 54 |
* butter |
| 55 |
|
| 56 |
1. carrots |
| 57 |
1. celery |
| 58 |
1. radishes |
| 59 |
``` |
| 60 |
|
| 61 |
* milk |
| 62 |
* eggs |
| 63 |
* butter |
| 64 |
|
| 65 |
1. carrots |
| 66 |
1. celery |
| 67 |
1. radishes |
| 68 |
|
| 69 |
## Links |
| 70 |
|
| 71 |
Linking to a URL or local file is easy: |
| 72 |
|
| 73 |
```markdown |
| 74 |
Use [mdBook](https://github.com/rust-lang/mdBook). |
| 75 |
|
| 76 |
Read about [mdBook](mdbook.md). |
| 77 |
|
| 78 |
And now [an mdBook link] that is not inline, unlike the above. |
| 79 |
|
| 80 |
A bare url: <https://www.rust-lang.org>. |
| 81 |
|
| 82 |
[an mdBook link]: https://github.com/rust-lang/mdBook |
| 83 |
``` |
| 84 |
|
| 85 |
Use [mdBook](https://github.com/rust-lang/mdBook). |
| 86 |
|
| 87 |
Read about [mdBook](mdbook.md). |
| 88 |
|
| 89 |
And now [an mdBook link] that is not inline, unlike the above. |
| 90 |
|
| 91 |
A bare url: <https://www.rust-lang.org>. |
| 92 |
|
| 93 |
[an mdBook link]: https://github.com/rust-lang/mdBook |
| 94 |
---- |
| 95 |
|
| 96 |
Relative links that end with `.md` will be converted to the `.html` extension. |
| 97 |
It is recommended to use `.md` links when possible. |
| 98 |
This is useful when viewing the Markdown file outside of mdBook, for example on GitHub or GitLab which render Markdown automatically. |
| 99 |
|
| 100 |
Links to `README.md` will be converted to `index.html`. |
| 101 |
This is done since some services like GitHub render README files automatically, but web servers typically expect the root file to be called `index.html`. |
| 102 |
|
| 103 |
You can link to individual headings with `#` fragments. |
| 104 |
For example, `mdbook.md#text-and-paragraphs` would link to the [Text and Paragraphs](#text-and-paragraphs) section above. |
| 105 |
The ID is created by transforming the heading such as converting to lowercase and replacing spaces with dashes. |
| 106 |
You can click on any heading and look at the URL in your browser to see what the fragment looks like. |
| 107 |
|
| 108 |
## Images |
| 109 |
|
| 110 |
Including images is simply a matter of including a link to them, much like in the _Links_ section above. The following markdown |
| 111 |
includes the Rust logo SVG image found in the `images` directory at the same level as this file: |
| 112 |
|
| 113 |
```markdown |
| 114 |
 |
| 115 |
``` |
| 116 |
|
| 117 |
Produces the following HTML when built with mdBook: |
| 118 |
|
| 119 |
```html |
| 120 |
<p><img src="images/rust-logo-blk.svg" alt="The Rust Logo" /></p> |
| 121 |
``` |
| 122 |
|
| 123 |
Which, of course displays the image like so: |
| 124 |
|
| 125 |
 |
| 126 |
|
| 127 |
## Extensions |
| 128 |
|
| 129 |
mdBook has several extensions beyond the standard CommonMark specification. |
| 130 |
|
| 131 |
### Strikethrough |
| 132 |
|
| 133 |
Text may be rendered with a horizontal line through the center by wrapping the |
| 134 |
text with one or two tilde characters on each side: |
| 135 |
|
| 136 |
```text |
| 137 |
An example of ~~strikethrough text~~. |
| 138 |
``` |
| 139 |
|
| 140 |
This example will render as: |
| 141 |
|
| 142 |
> An example of ~~strikethrough text~~. |
| 143 |
|
| 144 |
This follows the [GitHub Strikethrough extension][strikethrough]. |
| 145 |
|
| 146 |
### Footnotes |
| 147 |
|
| 148 |
A footnote generates a small numbered link in the text which when clicked |
| 149 |
takes the reader to the footnote text at the bottom of the item. The footnote |
| 150 |
label is written similarly to a link reference with a caret at the front. The |
| 151 |
footnote text is written like a link reference definition, with the text |
| 152 |
following the label. Example: |
| 153 |
|
| 154 |
```text |
| 155 |
This is an example of a footnote[^note]. |
| 156 |
|
| 157 |
[^note]: This text is the contents of the footnote, which will be rendered |
| 158 |
towards the bottom. |
| 159 |
``` |
| 160 |
|
| 161 |
This example will render as: |
| 162 |
|
| 163 |
> This is an example of a footnote[^note]. |
| 164 |
> |
| 165 |
> [^note]: This text is the contents of the footnote, which will be rendered |
| 166 |
> towards the bottom. |
| 167 |
|
| 168 |
The footnotes are automatically numbered based on the order the footnotes are |
| 169 |
written. |
| 170 |
|
| 171 |
### Tables |
| 172 |
|
| 173 |
Tables can be written using pipes and dashes to draw the rows and columns of |
| 174 |
the table. These will be translated to HTML table matching the shape. Example: |
| 175 |
|
| 176 |
```text |
| 177 |
| Header1 | Header2 | |
| 178 |
|---------|---------| |
| 179 |
| abc | def | |
| 180 |
``` |
| 181 |
|
| 182 |
This example will render similarly to this: |
| 183 |
|
| 184 |
| Header1 | Header2 | |
| 185 |
|---------|---------| |
| 186 |
| abc | def | |
| 187 |
|
| 188 |
See the specification for the [GitHub Tables extension][tables] for more |
| 189 |
details on the exact syntax supported. |
| 190 |
|
| 191 |
### Task lists |
| 192 |
|
| 193 |
Task lists can be used as a checklist of items that have been completed. |
| 194 |
Example: |
| 195 |
|
| 196 |
```md |
| 197 |
- [x] Complete task |
| 198 |
- [ ] Incomplete task |
| 199 |
``` |
| 200 |
|
| 201 |
This will render as: |
| 202 |
|
| 203 |
> - [x] Complete task |
| 204 |
> - [ ] Incomplete task |
| 205 |
|
| 206 |
See the specification for the [task list extension] for more details. |
| 207 |
|
| 208 |
### Smart punctuation |
| 209 |
|
| 210 |
Some ASCII punctuation sequences will be automatically turned into fancy Unicode |
| 211 |
characters: |
| 212 |
|
| 213 |
| ASCII sequence | Unicode | |
| 214 |
|----------------|---------| |
| 215 |
| `--` | – | |
| 216 |
| `---` | — | |
| 217 |
| `...` | … | |
| 218 |
| `"` | “ or ”, depending on context | |
| 219 |
| `'` | ‘ or ’, depending on context | |
| 220 |
|
| 221 |
So, no need to manually enter those Unicode characters! |
| 222 |
|
| 223 |
This feature is enabled by default. |
| 224 |
To disable it, see the [`output.html.smart-punctuation`] config option. |
| 225 |
|
| 226 |
[strikethrough]: https://github.github.com/gfm/#strikethrough-extension- |
| 227 |
[tables]: https://github.github.com/gfm/#tables-extension- |
| 228 |
[task list extension]: https://github.github.com/gfm/#task-list-items-extension- |
| 229 |
[`output.html.smart-punctuation`]: configuration/renderers.md#html-renderer-options |
| 230 |
|
| 231 |
### Heading attributes |
| 232 |
|
| 233 |
Headings can have a custom HTML ID and classes. This lets you maintain the same ID even if you change the heading's text, it also lets you add multiple classes in the heading. |
| 234 |
|
| 235 |
Example: |
| 236 |
```md |
| 237 |
# Example heading { #first .class1 .class2 } |
| 238 |
``` |
| 239 |
|
| 240 |
This makes the level 1 heading with the content `Example heading`, ID `first`, and classes `class1` and `class2`. Note that the attributes should be space-separated. |
| 241 |
|
| 242 |
More information can be found in the [heading attrs spec page](https://github.com/raphlinus/pulldown-cmark/blob/master/pulldown-cmark/specs/heading_attrs.txt). |
| 243 |
|
| 244 |
### Definition lists |
| 245 |
|
| 246 |
Definition lists can be used for things like glossary entries. The term is listed on a line by itself, followed by one or more definitions. Each definition must begin with a `:` (after 0-2 spaces). |
| 247 |
|
| 248 |
Example: |
| 249 |
|
| 250 |
```md |
| 251 |
term A |
| 252 |
: This is a definition of term A. Text |
| 253 |
can span multiple lines. |
| 254 |
|
| 255 |
term B |
| 256 |
: This is a definition of term B. |
| 257 |
: This has more than one definition. |
| 258 |
``` |
| 259 |
|
| 260 |
This will render as: |
| 261 |
|
| 262 |
term A |
| 263 |
: This is a definition of term A. Text |
| 264 |
can span multiple lines. |
| 265 |
|
| 266 |
term B |
| 267 |
: This is a definition of term B. |
| 268 |
: This has more than one definition. |
| 269 |
|
| 270 |
Terms are clickable just like headers, which will set the browser's URL to point directly to that term. |
| 271 |
|
| 272 |
See the [definition lists spec](https://github.com/pulldown-cmark/pulldown-cmark/blob/HEAD/pulldown-cmark/specs/definition_lists.txt) for more information on the specifics of the syntax. See the [Wikipedia guidelines for glossaries](https://en.wikipedia.org/wiki/Wikipedia:Manual_of_Style/Glossaries#General_guidelines_for_writing_glossaries) for some guidelines on how to write a glossary. |
| 273 |
|
| 274 |
This feature is enabled by default. |
| 275 |
To disable it, see the [`output.html.definition-lists`] config option. |
| 276 |
|
| 277 |
[`output.html.definition-lists`]: configuration/renderers.md#html-renderer-options |
| 278 |
|
| 279 |
### Admonitions |
| 280 |
|
| 281 |
An admonition is a special type of callout or notice block used to highlight important information. It is written as a blockquote with a special tag on the first line. |
| 282 |
|
| 283 |
```md |
| 284 |
> [!NOTE] |
| 285 |
> General information or additional context. |
| 286 |
|
| 287 |
> [!TIP] |
| 288 |
> A helpful suggestion or best practice. |
| 289 |
|
| 290 |
> [!IMPORTANT] |
| 291 |
> Key information that shouldn't be missed. |
| 292 |
|
| 293 |
> [!WARNING] |
| 294 |
> Critical information that highlights a potential risk. |
| 295 |
|
| 296 |
> [!CAUTION] |
| 297 |
> Information about potential issues that require caution. |
| 298 |
``` |
| 299 |
|
| 300 |
These will render as: |
| 301 |
|
| 302 |
> [!NOTE] |
| 303 |
> General information or additional context. |
| 304 |
|
| 305 |
> [!TIP] |
| 306 |
> A helpful suggestion or best practice. |
| 307 |
|
| 308 |
> [!IMPORTANT] |
| 309 |
> Key information that shouldn't be missed. |
| 310 |
|
| 311 |
> [!WARNING] |
| 312 |
> Critical information that highlights a potential risk. |
| 313 |
|
| 314 |
> [!CAUTION] |
| 315 |
> Information about potential issues that require caution. |
| 316 |
|
| 317 |
This feature is enabled by default. |
| 318 |
To disable it, see the [`output.html.admonitions`] config option. |
| 319 |
|
| 320 |
[`output.html.admonitions`]: configuration/renderers.md#html-renderer-options |
| 321 |
|
| 322 |
## Zoom-in |
| 323 |
|
| 324 |
All images in the chapters content have a "zoom-in" feature: you can click on it to make it bigger, and click it again to zoom out. You can focus the image with the keyboard as well, and press the spacebar to zoom in and out as well. |