Skip to content

Commit aa99472

Browse files
authored
Merge pull request #1520 from ehuss/mdbook-spec
Add mdbook-spec
2 parents 0ee9a66 + d376cba commit aa99472

File tree

7 files changed

+346
-74
lines changed

7 files changed

+346
-74
lines changed

.github/workflows/main.yml

+16-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,25 @@ on:
33
pull_request:
44
merge_group:
55

6+
env:
7+
MDBOOK_VERSION: 0.4.40
8+
# When updating, be sure to also update rust-lang/rust.
9+
MDBOOK_SPEC_VERSION: 0.1.0
10+
611
jobs:
712
test:
813
name: Test
914
runs-on: ubuntu-latest
1015
steps:
1116
- uses: actions/checkout@master
17+
- name: Cache
18+
uses: actions/cache@v4
19+
with:
20+
path: |
21+
~/.cargo/bin/
22+
~/.cargo/.crates.toml
23+
~/.cargo/.crates2.json
24+
key: ms-${MDBOOK_SPEC_VERSION}
1225
- name: Update rustup
1326
run: rustup self update
1427
- name: Install Rust
@@ -19,13 +32,15 @@ jobs:
1932
- name: Install mdbook
2033
run: |
2134
mkdir bin
22-
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.40/mdbook-v0.4.40-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin
35+
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v${MDBOOK_VERSION}/mdbook-v${MDBOOK_VERSION}-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin
2336
echo "$(pwd)/bin" >> $GITHUB_PATH
2437
- name: Report versions
2538
run: |
2639
rustup --version
2740
rustc -Vv
2841
mdbook --version
42+
- name: Install mdbook-spec
43+
run: cargo install --locked mdbook-spec@${MDBOOK_SPEC_VERSION}
2944
- name: Run tests
3045
run: mdbook test
3146
- name: Style checks

CONTRIBUTING.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ for the Reference. As such, we have the warning saying there's work that needs
1414
to be done. Eventually, we plan to make sure everything is well documented
1515
enough that we can remove the warning.
1616

17-
It is encouraged for you to read the [introduction] to familiarize yourself
18-
with the kind of content the reference is expected to contain and the
19-
conventions it uses. Also, the [style guide] provides more detailed guidelines
20-
for formatting and content.
17+
It is encouraged for you to read the [introduction] to familiarize yourself with
18+
the kind of content the reference is expected to contain and the conventions it
19+
uses. Also, the [Authoring Guide] provides more detailed guidelines for
20+
formatting and content.
2121

2222
## Critiquing the Reference
2323

@@ -68,9 +68,9 @@ This should include links to any relevant information, such as the
6868
stabilization PR, the RFC, the tracking issue, and anything else that would be
6969
helpful for writing the documentation.
7070

71+
[Authoring Guide]: docs/authoring.md
7172
[introduction]: src/introduction.md
7273
[issue tracker]: https://github.com/rust-lang/reference/issues
7374
[playpen]: https://play.rust-lang.org/
7475
[rust-lang/rust]: https://github.com/rust-lang/rust/
75-
[style guide]: STYLE.md
7676
[unstable]: https://doc.rust-lang.org/nightly/unstable-book/

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ what we have for now.
1212

1313
- Nightly Rust
1414
- [mdbook](https://rust-lang.github.io/mdBook/)
15+
- [`mdbook-spec`](https://github.com/rust-lang/spec/tree/main/mdbook-spec)
1516

1617
## Installing dependencies
1718

@@ -29,6 +30,12 @@ build the Reference:
2930
cargo install --locked mdbook
3031
```
3132

33+
Also install `mdbook-spec` which is a preprocessor which adds some Markdown extensions:
34+
35+
```sh
36+
cargo install --locked mdbook-spec
37+
```
38+
3239
## Building
3340

3441
To build the Reference, first clone the project:

STYLE.md

+2-68
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,5 @@
11
# Rust reference style guide
22

3-
Some conventions and content guidelines are specified in the [introduction].
4-
This document serves as a guide for editors and reviewers.
3+
See the [Authoring Guide] for details on the style used in the reference.
54

6-
There is a [`style-check`](style-check/) tool which is run in CI to check some of these. To use it locally, run `cargo run --manifest-path=style-check/Cargo.toml src`.
7-
8-
## Markdown formatting
9-
10-
* Use ATX-style heading with sentence case.
11-
* Use one line per sentence to make diffs nicer.
12-
Do not wrap long lines.
13-
* Use reference links, with shortcuts if appropriate.
14-
Place the sorted link reference definitions at the bottom of the file, or at the bottom of a section if there is an unusually large number of links that are specific to the section.
15-
16-
```
17-
Example of shortcut link: [enumerations]
18-
Example of reference link with label: [block expression][block]
19-
20-
[block]: expressions/block-expr.md
21-
[enumerations]: types/enum.md
22-
```
23-
24-
* Links should be relative with the `.md` extension.
25-
Links to other rust-lang books that are published with the reference or the standard library API should also be relative so that the linkchecker can validate them.
26-
* See the [Conventions] section for formatting callouts such as notes, edition differences, and warnings.
27-
* Formatting to avoid:
28-
* Avoid trailing spaces.
29-
* Avoid double blank lines.
30-
31-
### Code examples
32-
33-
Code examples should use code blocks with triple backticks.
34-
The language should always be specified (such as `rust`).
35-
36-
```rust
37-
println!("Hello!");
38-
```
39-
40-
See https://highlightjs.org/ for a list of supported languages.
41-
42-
Rust examples are tested via rustdoc, and should include the appropriate annotations when tests are expected to fail:
43-
44-
* `edition2015` or `edition2018` --- If it is edition-specific (see `book.toml` for the default).
45-
* `no_run` --- The example should compile successfully, but should not be executed.
46-
* `should_panic` --- The example should compile and run, but produce a panic.
47-
* `compile_fail` --- The example is expected to fail to compile.
48-
* `ignore` --- The example shouldn't be built or tested.
49-
This should be avoided if possible.
50-
Usually this is only necessary when the testing framework does not support it (such as external crates or modules, or a proc-macro), or it contains pseudo-code which is not valid Rust.
51-
An HTML comment such as `<!-- ignore: requires extern crate -->` should be placed before the example to explain why it is ignored.
52-
53-
See the [rustdoc documentation] for more detail.
54-
55-
## Language and grammar
56-
57-
* Use American English spelling.
58-
* Use Oxford commas.
59-
* Idioms and styling to avoid:
60-
* Avoid slashes for alternatives ("program/binary"), use conjunctions or rewrite it ("program or binary").
61-
* Avoid qualifying something as "in Rust", the entire reference is about Rust.
62-
63-
## Content
64-
65-
* Whenever there is a difference between editions, the differences should be called out with an "Edition Differences" block.
66-
The main text should stick to what is common between the editions.
67-
However, for large differences (such as "async"), the main text may contain edition-specific content as long as it is made clear which editions it applies to.
68-
69-
[conventions]: src/introduction.md#conventions
70-
[introduction]: src/introduction.md
71-
[rustdoc documentation]: https://doc.rust-lang.org/rustdoc/documentation-tests.html
5+
[Authoring Guide]: docs/authoring.md

book.toml

+2
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ smart-punctuation = true
1616

1717
[rust]
1818
edition = "2021"
19+
20+
[preprocessor.spec]

docs/authoring.md

+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# Authoring Guide
2+
3+
This document serves as a guide for editors and reviewers. Some conventions and content guidelines are specified in the [introduction].
4+
5+
[introduction]: ../src/introduction.md
6+
7+
## Markdown formatting
8+
9+
* Use [ATX-style headings][atx] (not Setext) with [sentence case].
10+
* Do not use tabs, only spaces.
11+
* Files must end with a newline.
12+
* 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.
13+
* If possible, avoid double blank lines.
14+
* Do not use indented code blocks; use 3+ backticks code blocks instead.
15+
* Code blocks should have an explicit language tag.
16+
* Do not wrap long lines. This helps with reviewing diffs of the source.
17+
* 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.
18+
* Links should be relative with the `.md` extension. Links to other rust-lang books that are published with the reference or the standard library API should also be relative so that the linkchecker can validate them.
19+
* 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.
20+
21+
```markdown
22+
Example of shortcut link: [enumerations]
23+
Example of reference link with label: [block expression][block]
24+
25+
[block]: expressions/block-expr.md
26+
[enumerations]: types/enum.md
27+
```
28+
* See the [Conventions] section for formatting callouts such as notes, edition differences, and warnings.
29+
30+
There are automated checks for some of these rules. Run `cargo run --manifest-path style-check/Cargo.toml -- src` to run them locally.
31+
32+
[atx]: https://spec.commonmark.org/0.31.2/#atx-headings
33+
[conventions]: ../src/introduction.md#conventions
34+
[sentence case]: https://apastyle.apa.org/style-grammar-guidelines/capitalization/sentence-case
35+
[smart punctuation]: https://rust-lang.github.io/mdBook/format/markdown.html#smart-punctuation
36+
37+
### Code examples
38+
39+
Code examples should use code blocks with triple backticks. The language should always be specified (such as `rust`).
40+
41+
```rust
42+
println!("Hello!");
43+
```
44+
45+
See <https://rust-lang.github.io/mdBook/format/theme/syntax-highlighting.html#supported-languages> for a list of supported languages.
46+
47+
Rust examples are tested via rustdoc, and should include the appropriate annotations:
48+
49+
* `edition2015` or `edition2018` --- If it is edition-specific (see `book.toml` for the default).
50+
* `no_run` --- The example should compile successfully, but should not be executed.
51+
* `should_panic` --- The example should compile and run, but produce a panic.
52+
* `compile_fail` --- The example is expected to fail to compile.
53+
* `ignore` --- The example shouldn't be built or tested. This should be avoided if possible. Usually this is only necessary when the testing framework does not support it (such as external crates or modules, or a proc-macro), or it contains pseudo-code which is not valid Rust. An HTML comment such as `<!-- ignore: requires extern crate -->` should be placed before the example to explain why it is ignored.
54+
* `Exxxx` --- If the example is expected to fail to compile with a specific error code, include that code so that rustdoc will check that the expected code is used.
55+
56+
See the [rustdoc documentation] for more detail.
57+
58+
[rustdoc documentation]: https://doc.rust-lang.org/rustdoc/documentation-tests.html
59+
60+
## Special markdown constructs
61+
62+
The following are extensions provided by [`mdbook-spec`](https://github.com/rust-lang/spec/tree/main/mdbook-spec).
63+
64+
### Rules
65+
66+
Most clauses should be preceded with a rule. Rules can be specified in the markdown source with the following on a line by itself:
67+
68+
```markdown
69+
r[foo.bar]
70+
```
71+
72+
The rule name should be lowercase, with periods separating from most general to most specific (like `r[array.repeat.zero]`).
73+
74+
Rules can be linked to by their ID using markdown such as `[foo.bar]`. There are automatic link references so that any rule can be referred to from any page in the book.
75+
76+
In the HTML, the rules are clickable just like headers.
77+
78+
### Standard library links
79+
80+
You should link to the standard library without specifying a URL in a fashion similar to [rustdoc intra-doc links][intra]. Some examples:
81+
82+
We can link to the page on `Option`:
83+
84+
```markdown
85+
[`std::option::Option`]
86+
```
87+
88+
In these links, generics are ignored and can be included:
89+
90+
```markdown
91+
[`std::option::Option<T>`]
92+
```
93+
94+
If we don't want the full path in the text, we can write:
95+
96+
```markdown
97+
[`Option`](std::option::Option)
98+
```
99+
100+
Macros can end in `!`. This can be helpful for disambiguation. For example, this refers to the macro rather than the module:
101+
102+
```markdown
103+
[`alloc::vec!`]
104+
```
105+
106+
Explicit namespace disambiguation is also supported:
107+
108+
```markdown
109+
[`std::vec`](mod@std::vec)
110+
```
111+
112+
[intra]: https://doc.rust-lang.org/rustdoc/write-documentation/linking-to-items-by-name.html
113+
114+
### Admonitions
115+
116+
Admonitions use a style similar to GitHub-flavored markdown, where the style name is placed at the beginning of a blockquote, such as:
117+
118+
```markdown
119+
> [!WARNING]
120+
> This is a warning.
121+
```
122+
123+
All this does is apply a CSS class to the blockquote. You should define the color or style of the rule in the `css/custom.css` file if it isn't already defined.
124+
125+
## Style
126+
127+
Idioms and styling to avoid:
128+
129+
* Use American English spelling.
130+
* Use Oxford commas.
131+
* Avoid slashes for alternatives ("program/binary"); use conjunctions or rewrite it ("program or binary").
132+
* Avoid qualifying something as "in Rust"; the entire reference is about Rust.
133+
134+
## Content guidelines
135+
136+
The following are guidelines for the content of the reference.
137+
138+
### Targets
139+
140+
The reference does not document which targets exist, or the properties of specific targets. The reference may refer to *platforms* or *target properties* where required by the language. Some examples:
141+
142+
* Conditional-compilation keys like `target_os` are specified to exist, but not what their values must be.
143+
* The `windows_subsystem` attribute specifies that it only works on Windows platforms.
144+
* Inline assembly and the `target_feature` attribute specify the architectures that are supported.
145+
146+
### Editions
147+
148+
The main text and flow should document only the current edition. Whenever there is a difference between editions, the differences should be called out with an "Edition Differences" block.

0 commit comments

Comments
 (0)