1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784
|
---
orphan: true
nosearch: true
myst:
substitutions:
reuse_key: "This is **included** text."
advanced_reuse_key: "This is a substitution that includes a code block:
```
code block
```"
---
# Documentation cheat sheet
The documentation files use a mixture of [Markdown](https://commonmark.org/) and [MyST](https://myst-parser.readthedocs.io/) syntax.
See the following sections for syntax help and conventions.
## Headings
```{list-table}
:header-rows: 1
* - Input
- Description
* - `# Title`
- Page title and H1 heading
* - `## Heading`
- H2 heading
* - `### Heading`
- H3 heading
* - `#### Heading`
- H4 heading
* - ...
- Further headings
```
Adhere to the following conventions:
- Do not use consecutive headings without intervening text.
- Use sentence style for headings (capitalize only the first word).
- Do not skip levels (for example, always follow an H2 with an H3, not an H4).
## Inline formatting
```{list-table}
:header-rows: 1
* - Input
- Output
* - `` {guilabel}`UI element` ``
- {guilabel}`UI element`
* - `` `code` ``
- `code`
* - `` {command}`command` ``
- {command}`command`
* - `*Italic*`
- *Italic*
* - `**Bold**`
- **Bold**
```
Adhere to the following conventions:
- Use italics sparingly. Common uses for italics are titles and names (for example, when referring to a section title that you cannot link to, or when introducing the name for a concept).
- Use bold sparingly. A common use for bold is UI elements ("Click **OK**"). Avoid using bold for emphasis and rather rewrite the sentence to get your point across.
## Code blocks
Start and end a code block with three back ticks:
```
You can specify the code language after the back ticks to enforce a specific lexer, but in many cases, the default lexer works just fine.
```{list-table}
:header-rows: 1
* - Input
- Output
* - ````
```
# Demonstrate a code block
code:
- example: true
```
````
- ```
# Demonstrate a code block
code:
- example: true
```
* - ````
```yaml
# Demonstrate a code block
code:
- example: true
```
````
- ```yaml
# Demonstrate a code block
code:
- example: true
```
```
To include back ticks in a code block, increase the number of surrounding back ticks:
```{list-table}
:header-rows: 1
* - Input
- Output
* -
`````
````
```
````
`````
-
````
```
````
```
## Links
How to link depends on if you are linking to an external URL or to another page in the documentation.
### External links
For external links, use only the URL, or Markdown syntax if you want to override the link text.
```{list-table}
:header-rows: 1
* - Input
- Output
* - `https://ubuntu.com/lxd`
- [{spellexception}`https://ubuntu.com/lxd`](https://ubuntu.com/lxd)
* - `[LXD](https://ubuntu.com/lxd)`
- [LXD](https://ubuntu.com/lxd)
```
To display a URL as text and prevent it from being linked, add a `<span></span>`:
```{list-table}
:header-rows: 1
* - Input
- Output
* - `https:/<span></span>/ubuntu.com/lxd`
- {spellexception}`https:/<span></span>/ubuntu.com/lxd`
```
### Internal references
For internal references, both Markdown and MyST syntax are supported. In most cases, you should use MyST syntax though, because it resolves the link text automatically and gives an indication of the link in GitHub rendering.
#### Referencing a page
To reference a documentation page, use MyST syntax to automatically extract the link text. When overriding the link text, use Markdown syntax.
```{list-table}
:header-rows: 1
* - Input
- Output
- Output on GitHub
- Status
* - `` {doc}`index` ``
- {doc}`index`
- {doc}<span></span>`index`
- Preferred.
* - `[](index)`
- [](index)
-
- Do not use.
* - `[LXD documentation](index)`
- [LXD documentation](index)
- [LXD documentation](index)
- Preferred when overriding the link text.
* - `` {doc}`LXD documentation <index>` ``
- {doc}`LXD documentation <index>`
- {doc}<span></span>`LXD documentation <index>`
- Alternative when overriding the link text.
```
Adhere to the following conventions:
- Override the link text only when it is necessary. If you can use the document title as link text, do so, because the text will then update automatically if the title changes.
- Never "override" the link text with the same text that would be generated automatically.
(a_section_target)=
#### Referencing a section
To reference a section within the documentation (on the same page or on another page), you can either add a target to it and reference that target, or you can use an automatically generated anchor in combination with the file name.
Adhere to the following conventions:
- Add targets for sections that are central and a "typical" place to link to, so you expect they will be linked frequently. For "one-off" links, you can use the automatically generated anchors.
- Override the link text only when it is necessary. If you can use the section title as link text, do so, because the text will then update automatically if the title changes.
- Never "override" the link text with the same text that would be generated automatically.
##### Using a target
You can add targets at any place in the documentation. However, if there is no heading or title for the targeted element, you must specify a link text.
(a_random_target)=
```{list-table}
:header-rows: 1
* - Input
- Output
- Output on GitHub
- Description
* - `(target_ID)=`
-
- \(target_ID\)=
- Adds the target ``target_ID``.
* - `` {ref}`a_section_target` ``
- {ref}`a_section_target`
- \{ref\}`a_section_target`
- References a target that has a title.
* - `` {ref}`link text <a_random_target>` ``
- {ref}`link text <a_random_target>`
- \{ref\}`link text <a_random_target>`
- References a target and specifies a title.
* - ``[`option name\](a_random_target)``
- [`option name`](a_random_target)
- [`option name`](a_random_target) (link is broken)
- Use Markdown syntax if you need markup on the link text.
```
##### Using an automatically generated anchor
You must use Markdown syntax to use automatically generated anchors.
You can leave out the file name when linking within the same file.
```{list-table}
:header-rows: 1
* - Input
- Output
- Output on GitHub
- Description
* - `[](#referencing-a-section)`
- [](#referencing-a-section)
-
- Do not use.
* - `[link text](#referencing-a-section)`
- [link text](#referencing-a-section)
- [link text](#referencing-a-section)
- Preferred when overriding the link text.
```
## Navigation
Every documentation page must be included as a subpage to another page in the navigation.
This is achieved with the [`toctree`](https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-toctree) directive in the parent page: <!-- wokeignore:rule=master -->
````
```{toctree}
:hidden:
subpage1
subpage2
```
````
If a page should not be included in the navigation, you can suppress the resulting build warning by putting the following instruction at the top of the file:
```
---
orphan: true
---
```
Use orphan pages sparingly and only if there is a clear reason for it.
## Lists
```{list-table}
:header-rows: 1
* - Input
- Output
* - ```
- Item 1
- Item 2
- Item 3
```
- - Item 1
- Item 2
- Item 3
* - ```
1. Step 1
1. Step 2
1. Step 3
```
- 1. Step 1
1. Step 2
1. Step 3
* - ```
1. Step 1
- Item 1
* Subitem
- Item 2
1. Step 2
1. Substep 1
1. Substep 2
```
- 1. Step 1
- Item 1
* Subitem
- Item 2
1. Step 2
1. Substep 1
1. Substep 2
```
Adhere to the following conventions:
- In numbered lists, use ``1.`` for all items to generate the step numbers automatically.
- Use `-` for unordered lists. When using nested lists, you can use `*` for the nested level.
### Definition lists
```{list-table}
:header-rows: 1
* - Input
- Output
* - ```
Term 1
: Definition
Term 2
: Definition
```
- Term 1
: Definition
Term 2
: Definition
```
## Tables
You can use standard Markdown tables. However, using the rST [list table](https://docutils.sourceforge.io/docs/ref/rst/directives.html#list-table) syntax is usually much easier.
Both markups result in the following output:
```{list-table}
:header-rows: 1
* - Header 1
- Header 2
* - Cell 1
Second paragraph cell 1
- Cell 2
* - Cell 3
- Cell 4
```
### Markdown tables
```
| Header 1 | Header 2 |
|------------------------------------|----------|
| Cell 1<br><br>2nd paragraph cell 1 | Cell 2 |
| Cell 3 | Cell 4 |
```
### List tables
````
```{list-table}
:header-rows: 1
* - Header 1
- Header 2
* - Cell 1
2nd paragraph cell 1
- Cell 2
* - Cell 3
- Cell 4
```
````
## Notes
```{list-table}
:header-rows: 1
* - Input
- Output
* - ````
```{note}
A note.
```
````
- ```{note}
A note.
```
* - ````
```{tip}
A tip.
```
````
- ```{tip}
A tip.
```
* - ````
```{important}
Important information
```
````
- ```{important}
Important information.
```
* - ````
```{caution}
This might damage your hardware!
```
````
- ```{caution}
This might damage your hardware!
```
```
Adhere to the following conventions:
- Use notes sparingly.
- Only use the following note types: `note`, `tip`, `important`, `caution`
- Only use a caution if there is a clear hazard of hardware damage or data loss.
## Images
```{list-table}
:header-rows: 1
* - Input
- Output
* - ```

```
- 
* - ````
```{figure} https://documentation.ubuntu.com/lxd/en/latest/_static/tag.png
:width: 100px
:alt: Alt text
Figure caption
```
````
- ```{figure} https://documentation.ubuntu.com/lxd/en/latest/_static/tag.png
:width: 100px
:alt: Alt text
Figure caption
```
```
Adhere to the following conventions:
- For pictures in the `doc` directory, start the path with `/` (for example, `/images/image.png`).
- Use PNG format for screenshots and SVG format for graphics.
## Reuse
A big advantage of MyST in comparison to plain Markdown is that it allows to reuse content.
### Substitution
To reuse sentences or paragraphs without too much markup and special formatting, use substitutions.
Substitutions can be defined in the following locations:
- In the `substitutions.yaml` file. Substitutions defined in this file are available in all documentation pages.
- At the top of a single file in the following format:
````
---
myst:
substitutions:
reuse_key: "This is **included** text."
advanced_reuse_key: "This is a substitution that includes a code block:
```
code block
```"
---
````
You can combine both options by defining a default substitution in `reuse/substitutions.py` and overriding it at the top of a file.
```{list-table}
:header-rows: 1
* - Input
- Output
* - `{{reuse_key}}`
- {{reuse_key}}
* - `{{advanced_reuse_key}}`
- {{advanced_reuse_key}}
```
Adhere to the following convention:
- Substitutions do not work on GitHub. Therefore, use key names that indicate the included text (for example, `note_not_supported` instead of `reuse_note`).
### File inclusion
To reuse longer sections or text with more advanced markup, you can put the content in a separate file and include the file or parts of the file in several locations.
You cannot put any targets into the content that is being reused (because references to this target would be ambiguous then). You can, however, put a target right before including the file.
By combining file inclusion and substitutions, you can even replace parts of the included text.
`````{list-table}
:header-rows: 1
* - Input
- Output
* - ````
% Include parts of the content from file [../README.md](../README.md)
```{include} ../README.md
:start-after: Installing LXD from packages
:end-before: For more instructions on installing LXD
```
````
-
% Include parts of the content from file [../README.md](../README.md)
```{include} ../README.md
:start-after: Installing LXD from packages
:end-before: For more instructions on installing LXD
```
`````
Adhere to the following convention:
- File inclusion does not work on GitHub. Therefore, always add a comment linking to the included file.
- To select parts of the text, add HTML comments for the start and end points and use `:start-after:` and `:end-before:`, if possible. You can combine `:start-after:` and `:end-before:` with `:start-line:` and `:end-line:` if required. Using only `:start-line:` and `:end-line:` is error-prone though.
## Tabs
``````{list-table}
:header-rows: 1
* - Input
- Output
* - `````
````{tabs}
```{group-tab} Tab 1
Content Tab 1
```
```{group-tab} Tab 2
Content Tab 2
```
````
`````
- ````{tabs}
```{group-tab} Tab 1
Content Tab 1
```
```{group-tab} Tab 2
Content Tab 2
```
````
``````
## Collapsible sections
There is no support for details sections in rST, but you can insert HTML to create them.
```{list-table}
:header-rows: 1
* - Input
- Output
* - ```
<details>
<summary>Details</summary>
Content
</details>
```
- <details>
<summary>Details</summary>
Content
</details>
```
## Glossary
You can define glossary terms in any file. Ideally, all terms should be collected in one glossary file though, and they can then be referenced from any file.
`````{list-table}
:header-rows: 1
* - Input
- Output
* - ````
```{glossary}
example term
Definition of the example term.
```
````
- ```{glossary}
example term
Definition of the example term.
```
* - ``{term}`example term` ``
- {term}`example term`
`````
## More useful markup
`````{list-table}
:header-rows: 1
* - Input
- Output
* - ````
```{versionadded} X.Y
```
````
- ```{versionadded} X.Y
```
* - `` {abbr}`API (Application Programming Interface)` ``
- {abbr}`API (Application Programming Interface)`
`````
## Custom extensions
The documentation uses some custom extensions.
### Related links
You can add links to related websites to the sidebar by adding the following field at the top of the page:
relatedlinks: https://github.com/canonical/lxd-sphinx-extensions, [RTFM](https://www.google.com)
To override the title, use Markdown syntax. Note that spaces are ignored; if you need spaces in the title, replace them with ` `, and include the value in quotes if Sphinx complains about the metadata value because it starts with `[`.
To add a link to a Discourse topic, add the following field at the top of the page (where `12345` is the ID of the Discourse topic):
discourse: 12345
### YouTube links
To add a link to a YouTube video, use the following directive:
`````{list-table}
:header-rows: 1
* - Input
- Output
* - ````
```{youtube} https://www.youtube.com/watch?v=iMLiK1fX4I0
:title: Demo
```
````
- ```{youtube} https://www.youtube.com/watch?v=iMLiK1fX4I0
:title: Demo
```
`````
The video title is extracted automatically and displayed when hovering over the link.
To override the title, add the `:title:` option.
### Spelling exceptions
If you need to use a word that does not comply to the spelling conventions, but is correct in a certain context, you can exempt it from the spelling checker by surrounding it with `{spellexception}`.
```{list-table}
:header-rows: 1
* - Input
- Output
* - `` {spellexception}`PurposelyWrong` ``
- {spellexception}`PurposelyWrong`
```
### Terminal output
To show a terminal view with commands and output, use the following directive:
`````{list-table}
:header-rows: 1
* - Input
- Output
* - ````
```{terminal}
:input: command number one
:user: root
:host: vm
output line one
output line two
:input: another command
more output
```
````
- ```{terminal}
:input: command number one
:user: root
:host: vm
output line one
output line two
:input: another command
more output
```
`````
Input is specified as the `:input:` option (or prefixed with `:input:` as part of the main content of the directive).
Output is the main content of the directive.
To override the prompt (`user@host:~$` by default), specify the `:user:` and/or `:host:` options.
To make the terminal scroll horizontally instead of wrapping long lines, add `:scroll:`.
|