toolkit for mdBook [mirror of my GitHub repo] docs.tonywu.dev/mdbookkit/
permalinks rust-analyzer mdbook
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

[link-forever] check canonical URLs

+597 -139
+1 -1
.cargo/config.toml
··· 1 1 [alias] 2 - bin = ["run", "--release", "--package", "cargo-bin", "--"] 2 + bin = ["run", "--quiet", "--release", "--package", "cargo-bin", "--"]
+3 -2
.github/workflows/ci.yml
··· 7 7 8 8 pull_request: 9 9 10 + schedule: 11 + - cron: "27 0 * * *" 12 + 10 13 env: 11 14 CARGO_TERM_COLOR: always 12 15 ··· 19 22 matrix: 20 23 toolchain: 21 24 - "stable" 22 - - "1.81.0" 23 25 24 26 steps: 25 27 - uses: actions/checkout@v4 ··· 76 78 ra-version: 77 79 - "2025-03-17" 78 80 - "2025-03-04" 79 - - "2025-02-17" # 1.85.0 80 81 - "nightly" 81 82 82 83 steps:
+4 -2
Cargo.toml
··· 1 1 [workspace.package] 2 + publish = false 3 + 2 4 authors = ["Tony Wu <tonywu6@protonmail.com>"] 3 - edition = "2021" 4 5 license = "MIT OR Apache-2.0" 5 - publish = false 6 6 repository = "https://github.com/tonywu6/mdbookkit" 7 + 8 + edition = "2021" 7 9 rust-version = "1.81.0" 8 10 9 11 [profile.dev.package]
+1
README.md
··· 1 + # mdbookkit
+11 -3
crates/mdbookkit/Cargo.toml
··· 1 1 [package] 2 2 name = "mdbookkit" 3 + publish = true 3 4 version = "0.1.0" 4 5 5 6 authors.workspace = true 6 - edition.workspace = true 7 + description = "Toolkit for mdBook." 7 8 license.workspace = true 8 - publish.workspace = true 9 + readme = "README.md" 9 10 repository.workspace = true 11 + 12 + edition.workspace = true 10 13 rust-version.workspace = true 11 14 12 15 autobins = false ··· 48 51 tokio-util = { version = "0.7.13", features = ["compat"], optional = true } 49 52 toml = { workspace = true, optional = true } 50 53 tower = { version = "0.5.2", optional = true } 51 - url = { workspace = true, optional = true } 54 + url = { workspace = true, features = ["serde"], optional = true } 52 55 53 56 [dev-dependencies] 54 57 insta = { workspace = true } ··· 104 107 common-cli = ["dep:clap", "dep:mdbook", "dep:toml"] 105 108 106 109 default = [] 110 + 111 + # aliases 112 + 113 + mdbook-link-forever = ["link-forever"] 114 + mdbook-rustdoc-link = ["rustdoc-link"] 107 115 108 116 [[bin]] 109 117 name = "mdbook-rustdoc-link"
+47
crates/mdbookkit/README.md
··· 1 + # mdbookkit — _toolkit for 📖 [mdBook]!_ 2 + 3 + [`mdbookkit`] provides quality-of-life plugins that you can use in your mdBook project. 4 + 5 + Right now, there are two mdBook [preprocessors], both for generating **correct and 6 + versioned** external links from **easy-to-write** markup. 7 + 8 + - [**`mdbook-rustdoc-link`**](https://tonywu6.github.io/mdbookkit/rustdoc-link) 9 + 10 + _rustdoc_-style linking for Rust APIs: write types and function names, get links to 11 + docs.rs 12 + 13 + - [**`mdbook-link-forever`**](https://tonywu6.github.io/mdbookkit/link-forever) 14 + 15 + _Permalinks_ for your source tree: write relative paths, get links to GitHub. 16 + 17 + > [!TIP] 18 + > 19 + > Preprocessors are standalone programs that mdBook invokes to transform your Markdown 20 + > sources before rendering them. 21 + 22 + ## Installation 23 + 24 + If you are interested in any of these plugins, visit their respective pages for usage 25 + instructions, linked above. 26 + 27 + If you want to install all of them: 28 + 29 + ```bash 30 + cargo install mdbookkit --all-features 31 + ``` 32 + 33 + Precompiled binaries are also available from [GitHub releases][gh-releases]. 34 + 35 + ## License 36 + 37 + This project is released under the [Apache 2.0 License](/LICENSE-APACHE.md) and the 38 + [MIT License](/LICENSE-MIT.md). 39 + 40 + <!-- prettier-ignore-start --> 41 + 42 + [mdBook]: https://rust-lang.github.io/mdBook/ 43 + [`mdbookkit`]: https://crates.io/crates/mdbookkit 44 + [preprocessors]: https://rust-lang.github.io/mdBook/format/configuration/preprocessors.html 45 + [gh-releases]: https://github.com/tonywu6/mdbookkit/releases 46 + 47 + <!-- prettier-ignore-end -->
+4
crates/mdbookkit/tests/snaps/rustdoc_link/getting-started.snap
··· 1 1 --- 2 2 source: crates/mdbookkit/tests/rustdoc_link.rs 3 + assertion_line: 31 3 4 expression: output 4 5 --- 5 6 # Getting started ··· 22 23 ``` 23 24 cargo install mdbookkit --features rustdoc-link 24 25 ``` 26 + 27 + Or you can grab precompiled binaries from [GitHub releases][gh-releases]. 25 28 26 29 ## Configure 27 30 ··· 92 95 [ra-install]: https://rust-analyzer.github.io/book/rust_analyzer_binary.html 93 96 [open-docs]: https://rust-analyzer.github.io/book/features.html#open-docs 94 97 [ra-extension]: https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer 98 + [gh-releases]: https://github.com/tonywu6/mdbookkit/releases 95 99 96 100 <!-- prettier-ignore-end -->
+7 -6
crates/mdbookkit/tests/snaps/rustdoc_link/getting-started.stderr.snap
··· 1 1 --- 2 - source: crates/rustdoc-link/tests/lib.rs 2 + source: crates/mdbookkit/tests/rustdoc_link.rs 3 + assertion_line: 44 3 4 expression: report 4 5 --- 5 6 info: successfully resolved all links 6 - ╭─[getting-started:50:6] 7 - 49 │ 8 - 50 │ Like [`std::thread::spawn`], [`tokio::task::spawn`] returns a 7 + ╭─[getting-started:52:6] 8 + 51 │ 9 + 52 │ Like [`std::thread::spawn`], [`tokio::task::spawn`] returns a 9 10 · ───────────┬────────── ───────────┬────────── 10 11 · │ ╰── https://docs.rs/tokio/1.44.1/tokio/task/spawn/fn.spawn.html 11 12 · ╰── https://doc.rust-lang.org/stable/std/thread/fn.spawn.html 12 - 51 │ [`JoinHandle`][tokio::task::JoinHandle] struct. 13 + 53 │ [`JoinHandle`][tokio::task::JoinHandle] struct. 13 14 · ───────────────────┬─────────────────── 14 15 · ╰── https://docs.rs/tokio/1.44.1/tokio/runtime/task/join/struct.JoinHandle.html 15 - 52 │ 16 + 54 │ 16 17 ╰────
+3 -1
crates/mdbookkit/tests/snaps/rustdoc_link/rustdoc-link.snap
··· 1 1 --- 2 2 source: crates/mdbookkit/tests/rustdoc_link.rs 3 + assertion_line: 31 3 4 expression: output 4 5 --- 5 6 # mdbook-rustdoc-link ··· 44 45 45 46 For **writing documentation** — 46 47 47 - - To know more about how the preprocessor is resolving items into links, see 48 + - To know more about how the preprocessor is resolving items into links, including 49 + [feature-gated items](rustdoc-link/name-resolution.md#feature-gated-items), see 48 50 [Name resolution](rustdoc-link/name-resolution.md). 49 51 - To know how to link to other types of items like 50 52 [functions, macros](rustdoc-link/supported-syntax.md#functions-and-macros), and
+3
docs/README.md
··· 1 + # mdbookkit docs 2 + 3 + For best results, see <https://tonywu6.github.io/mdbookkit/>.
+9 -7
docs/book.toml
··· 8 8 [build] 9 9 build-dir = "dist" 10 10 create-missing = false 11 - extra-watch-dirs = ["app"] 11 + extra-watch-dirs = ["app", "../crates/mdbookkit"] 12 12 13 13 [rust] 14 14 edition = "2021" ··· 27 27 28 28 [preprocessor.rustdoc-link-options] 29 29 before = ["rustdoc-link"] 30 - command = "cargo run --package util-clap-reflect -- --reflect rustdoc-link-options" 30 + command = "cargo run --quiet --package util-clap-reflect -- --reflect rustdoc-link-options" 31 31 32 32 [preprocessor.link-forever-options] 33 33 before = ["rustdoc-link"] 34 - command = "cargo run --package util-clap-reflect -- --reflect link-forever-options" 34 + command = "cargo run --quiet --package util-clap-reflect -- --reflect link-forever-options" 35 35 36 36 [preprocessor.rustdoc-link] 37 37 after = ["links"] 38 38 cache-dir = "build" 39 39 cargo-features = ["clap/unstable-doc"] 40 - command = "cargo run --package mdbookkit --bin mdbook-rustdoc-link --features=rustdoc-link --release" 40 + command = "cargo run --quiet --package mdbookkit --bin mdbook-rustdoc-link --all-features --release" 41 41 manifest-dir = "." 42 - rust-analyzer = "cargo run --package util-rust-analyzer -- analyzer" 42 + rust-analyzer = "cargo run --quiet --package util-rust-analyzer --all-features -- analyzer" 43 43 44 44 [preprocessor.link-forever] 45 45 after = ["rustdoc-link"] 46 46 always-link = [".rs"] 47 - command = "cargo run --package mdbookkit --bin mdbook-link-forever --features=link-forever --release" 47 + book-url = "https://tonywu6.github.io/mdbookkit/" 48 + command = "cargo run --quiet --package mdbookkit --bin mdbook-link-forever --all-features --release" 48 49 49 50 [preprocessor.rust-analyzer-version] 50 51 after = ["rustdoc-link"] 51 - command = "cargo run --package util-rust-analyzer --features=ra-version -- version" 52 + command = "cargo run --quiet --package util-rust-analyzer --all-features -- version" 52 53 53 54 [preprocessor.alerts] 54 55 after = ["rustdoc-link"] 56 + command = "cargo bin mdbook-alerts" 55 57 56 58 [preprocessor.app] 57 59 command = "deno run -A app/build/preprocessor.ts"
+2
docs/src/SUMMARY.md
··· 19 19 20 20 - [link-forever](link-forever.md) 21 21 - [Feature sheet](link-forever/features.md) 22 + - [`{{#include}}` workarounds](link-forever/working-with-include.md) 22 23 - [Configuration](link-forever/configuration.md) 24 + - [Known issues](link-forever/known-issues.md)
+1 -1
docs/src/index.md
··· 1 - # mdbookkit 1 + {{#include ../../crates/mdbookkit/README.md}}
+2 -1
docs/src/rustdoc-link.md
··· 40 40 41 41 For **writing documentation** — 42 42 43 - - To know more about how the preprocessor is resolving items into links, see 43 + - To know more about how the preprocessor is resolving items into links, including 44 + [feature-gated items](rustdoc-link/name-resolution.md#feature-gated-items), see 44 45 [Name resolution](rustdoc-link/name-resolution.md). 45 46 - To know how to link to other types of items like 46 47 [functions, macros](rustdoc-link/supported-syntax.md#functions-and-macros), and
+5
docs/src/rustdoc-link/caching.md
··· 50 50 51 51 ## How it works 52 52 53 + > [!NOTE] 54 + > 55 + > The following are implementation details. See 56 + > [rustdoc_link/cache.rs](/crates/mdbookkit/src/bin/rustdoc_link/cache.rs). 57 + 53 58 The effectiveness of this mechanism is based on the following assumptions: 54 59 55 60 - Most of the changes made during authoring don't actually involve item links.
+3
docs/src/rustdoc-link/getting-started.md
··· 19 19 cargo install mdbookkit --features rustdoc-link 20 20 ``` 21 21 22 + Or you can grab precompiled binaries from [GitHub releases][gh-releases]. 23 + 22 24 ## Configure 23 25 24 26 Configure your `book.toml` to use it as a [preprocessor]: ··· 88 90 [ra-install]: https://rust-analyzer.github.io/book/rust_analyzer_binary.html 89 91 [open-docs]: https://rust-analyzer.github.io/book/features.html#open-docs 90 92 [ra-extension]: https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer 93 + [gh-releases]: https://github.com/tonywu6/mdbookkit/releases 91 94 92 95 <!-- prettier-ignore-end -->
+2 -1
docs/src/rustdoc-link/name-resolution.md
··· 126 126 127 127 > [!NOTE] 128 128 > 129 - > The following are implementation details. 129 + > The following are implementation details. See 130 + > [rustdoc_link/mod.rs](/crates/mdbookkit/src/bin/rustdoc_link/mod.rs). 130 131 131 132 `mdbook-rustdoc-link` parses your book and collects every link that looks like a Rust 132 133 item. Then it synthesizes a Rust function that spells out all the items, which looks
+16 -6
utils/clap-reflect/src/main.rs
··· 1 + //! Derive Markdown documentation from [`clap::Parser`]s. 2 + //! 3 + //! Functions as an mdBook preprocessor that replaces 4 + //! `<cmd-option>(autogenerated)</cmd-option>` with said documentation. 5 + //! 6 + //! - [mdbookkit::bin::rustdoc_link::env::Config] 7 + //! - [mdbookkit::bin::link_forever::Config] 8 + 1 9 use std::io::{Read, Write}; 2 10 3 11 use anyhow::Result; ··· 6 14 use minijinja::render; 7 15 use serde::Serialize; 8 16 9 - use tap::Pipe; 17 + use tap::{Pipe, Tap}; 10 18 11 19 #[derive(Parser, Debug, Clone)] 12 20 struct Program { ··· 81 89 key: String, 82 90 help: String, 83 91 description: String, 84 - type_id: Option<String>, 92 + type_id: Option<(String, String)>, 85 93 default: Option<String>, 86 94 choices: Vec<(String, String)>, 87 95 } ··· 186 194 <th style="text-align: left;">Type</th> 187 195 <td> 188 196 189 - [`{{ option.type_id }}`] 197 + [`{{ option.type_id[0] }}`][{{ option.type_id[1] }}] 190 198 191 199 </td> 192 200 </tr> ··· 218 226 let type_id = if cfg!(debug_assertions) { 219 227 let ty = format!("{:?}", opt.get_value_parser().type_id()) 220 228 .replace("alloc::string::", ""); 229 + let name = ty.split("::").last().unwrap(); 221 230 if matches!(action, ArgAction::Append) { 222 - Some(format!("Vec<{ty}>")) 231 + Some((format!("Vec<{name}>"), format!("Vec<{ty}>"))) 223 232 } else { 224 - Some(ty) 233 + Some((name.to_owned(), ty)) 225 234 } 226 235 } else { 227 236 None ··· 263 272 choices, 264 273 } 265 274 }) 266 - .collect::<Vec<_>>(); 275 + .collect::<Vec<_>>() 276 + .tap_mut(|opts| opts.sort_by(|a, b| a.key.cmp(&b.key))); 267 277 268 278 Ok(render!(template, options)) 269 279 }
+5 -1
utils/mdbook-socials/src/main.rs
··· 1 + //! Postprocess mdBook HTML output to add OpenGraph metadata, for social images, etc. 2 + //! 3 + //! mdBook doesn't support frontmatters yet, so this cannot be a preprocessor. 4 + 1 5 use std::{collections::HashMap, path::PathBuf}; 2 6 3 7 use anyhow::{Context, Result}; ··· 87 91 88 92 Settings { 89 93 element_content_handlers: vec![ 90 - text!("main > h1", |text| { 94 + text!("main > h1:first-of-type", |text| { 91 95 title.push_str(text.as_str()); 92 96 Ok(()) 93 97 }),
+6
utils/rust-analyzer/src/main.rs
··· 1 + //! Download a copy of rust-analyzer to /.bin to use in testing. 2 + //! 3 + //! Version can be controlled with the `RA_VERSION` environment variable. 4 + 1 5 use std::{ 2 6 fs, io, 3 7 os::unix::fs::PermissionsExt, ··· 156 160 } 157 161 } 158 162 163 + /// Preprocessor to replace `<ra-version>(version)</ra-version>` with the currently 164 + /// used RA version. Used in docs. 159 165 #[cfg(feature = "ra-version")] 160 166 mod ra_version { 161 167 use std::io::{Read, Write};
+2
utils/testing/src/lib.rs
··· 1 + //! Test helpers. 2 + 1 3 use std::path::Path; 2 4 3 5 use anyhow::Result;