|
| 1 | +# Markdown |
| 2 | + |
| 3 | +There are automated checks for some of these rules. Run [`cargo xtask style-check`] to run them locally. |
| 4 | + |
| 5 | +## Formatting style |
| 6 | + |
| 7 | +- Use [ATX-style headings][atx] (not Setext) with [sentence case]. |
| 8 | +- Do not use tabs, only spaces. |
| 9 | +- Files must end with a newline. |
| 10 | +- Lines must not end with spaces. Double spaces have semantic meaning, but can be invisible. Use a trailing backslash if you need a hard line break. |
| 11 | +- If possible, avoid double blank lines. |
| 12 | +- Do not wrap long lines. This helps with reviewing diffs of the source. |
| 13 | +- Use [smart punctuation] instead of Unicode characters. For example, use `---` for em-dash instead of the Unicode character. Characters like em-dash can be difficult to see in a fixed-width editor, and some editors may not have easy methods to enter such characters. |
| 14 | +- See the [admonitions chapter] for formatting callouts such as notes, edition differences, and warnings. |
| 15 | + |
| 16 | +## Code blocks |
| 17 | + |
| 18 | +- Do not use indented code blocks; use 3+ backticks code blocks instead. |
| 19 | +- Code blocks should have an explicit language tag. |
| 20 | + |
| 21 | +## Links |
| 22 | + |
| 23 | +See the [links chapter] for more information about linking. |
| 24 | + |
| 25 | +- Links to other chapters should be relative with the `.md` extension. |
| 26 | +- Links to other rust-lang books that are published with the Reference should also be relative so that the linkchecker can validate them. See [outside book links]. |
| 27 | +- Links to the standard library should use rustdoc-style links described in [standard library links]. |
| 28 | +- The use of reference links is preferred, with shortcuts if appropriate. Place the sorted link reference definitions at the bottom of the file or at the bottom of a section if there are an unusually large number of links that are specific to the section. |
| 29 | + |
| 30 | + ```markdown |
| 31 | + Example of shortcut link: [enumerations] |
| 32 | + Example of reference link with label: [block expression][block] |
| 33 | + |
| 34 | + [block]: expressions/block-expr.md |
| 35 | + [enumerations]: types/enum.md |
| 36 | + ``` |
| 37 | + |
| 38 | +[`cargo xtask style-check`]: ../tests.md#style-checks |
| 39 | +[admonitions chapter]: admonitions.md |
| 40 | +[atx]: https://spec.commonmark.org/0.31.2/#atx-headings |
| 41 | +[links chapter]: ../links.md |
| 42 | +[outside book links]: ../links.md#outside-book-links |
| 43 | +[sentence case]: https://apastyle.apa.org/style-grammar-guidelines/capitalization/sentence-case |
| 44 | +[smart punctuation]: https://rust-lang.github.io/mdBook/format/markdown.html#smart-punctuation |
| 45 | +[standard library links]: ../links.md#standard-library-links |
0 commit comments