Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite the automatic std link translation, and switch to automatic links #1578

Merged
merged 7 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ To build the Reference locally (in `build/`) and open it in a web
browser, run:

```sh
mdbook build --open
SPEC_RELATIVE=0 mdbook build --open
```

This will open a browser with a websocket live-link to automatically reload whenever the source is updated.

You can also open any current build of the reference by running:
The `SPEC_RELATIVE=0` environment variable makes links to the standard library go to <https://doc.rust-lang.org/> instead of being relative, which is useful when viewing locally since you normally don't have a copy of the standard library.

You can also use mdbook's live webserver option, which will automatically rebuild the book and reload your web browser whenever a source file is modified:

```sh
mdbook serve --open
SPEC_RELATIVE=0 mdbook serve --open
```
2 changes: 1 addition & 1 deletion book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ smart-punctuation = true
edition = "2021"

[preprocessor.spec]
command = "cargo run --manifest-path mdbook-spec/Cargo.toml"
command = "cargo run --release --manifest-path mdbook-spec/Cargo.toml"

[build]
extra-watch-dirs = ["mdbook-spec/src"]
9 changes: 9 additions & 0 deletions docs/authoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ Explicit namespace disambiguation is also supported:
[`std::vec`](mod@std::vec)
```

Beware there are some limitations, for example:

- Links to rexports from `std_arch` don't work due to <https://github.com/rust-lang/rust/issues/96506>.
- Links to keywords aren't supported.
- Links to trait impls where the trait is not in the prelude doesn't work. Traits must be in scope, and there currently isn't a way to add those.
- If there are multiple generic implementations, it will link to one randomly (see <https://github.com/rust-lang/rust/issues/76895>).

When running into a rustdoc limitation, consider manually linking to the correct page using a relative link. For example, `../std/arch/macro.is_x86_feature_detected.html`.

[intra]: https://doc.rust-lang.org/rustdoc/write-documentation/linking-to-items-by-name.html

### Admonitions
Expand Down
1 change: 1 addition & 0 deletions mdbook-spec/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions mdbook-spec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ anyhow = "1.0.79"
mdbook = { version = "0.4.36", default-features = false }
once_cell = "1.19.0"
pathdiff = "0.2.1"
# Try to keep in sync with mdbook.
pulldown-cmark = { version = "0.10.3", default-features = false }
regex = "1.9.4"
semver = "1.0.21"
serde_json = "1.0.113"
Expand Down
5 changes: 4 additions & 1 deletion mdbook-spec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ impl Preprocessor for Spec {
}
ch.content = self.rule_definitions(&ch, &mut found_rules);
ch.content = self.admonitions(&ch);
ch.content = std_links::std_links(&ch);
});
// This is a separate pass because it relies on the modifications of
// the previous passes.
Expand All @@ -167,6 +166,10 @@ impl Preprocessor for Spec {
}
ch.content = self.auto_link_references(&ch, &found_rules);
});
// Final pass will resolve everything as a std link (or error if the
// link is unknown).
std_links::std_links(&mut book);

Ok(book)
}
}
Loading