Skip to content

Commit 97b6a35

Browse files
authoredDec 30, 2021
Merge pull request #1710 from ehuss/update-guide
Update documentation
2 parents f3e5fce + f2fba30 commit 97b6a35

22 files changed

+828
-614
lines changed
 

‎CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,4 @@ The following are instructions for updating [highlight.js](https://highlightjs.o
127127
1. Compare the language list that it spits out to the one in [`syntax-highlighting.md`](https://github.com/camelid/mdBook/blob/master/guide/src/format/theme/syntax-highlighting.md). If any are missing, add them to the list and rebuild (and update these docs). If any are added to the common set, add them to `syntax-highlighting.md`.
128128
1. Copy `build/highlight.min.js` to mdbook's directory [`highlight.js`](https://github.com/rust-lang/mdBook/blob/master/src/theme/highlight.js).
129129
1. Be sure to check the highlight.js [CHANGES](https://github.com/highlightjs/highlight.js/blob/main/CHANGES.md) for any breaking changes. Breaking changes that would affect users will need to wait until the next major release.
130-
1. Build mdbook with the new file and build some books with the new version and compare the output with a variety of languages to see if anything changes. (TODO: It would be nice to have a demo file in the repo to help with this.)
130+
1. Build mdbook with the new file and build some books with the new version and compare the output with a variety of languages to see if anything changes. The [test_book](https://github.com/rust-lang/mdBook/tree/master/test_book) contains a chapter with many languages to examine.

‎README.md

+3-221
Original file line numberDiff line numberDiff line change
@@ -6,233 +6,15 @@
66

77
mdBook is a utility to create modern online books from Markdown files.
88

9+
Check out the **[User Guide]** for a list of features and installation and usage information.
10+
The User Guide also serves as a demonstration to showcase what a book looks like.
911

10-
## What does it look like?
11-
12-
The [User Guide] for mdBook has been written in Markdown and is using mdBook to
13-
generate the online book-like website you can read. The documentation uses the
14-
latest version on GitHub and showcases the available features.
15-
16-
## Installation
17-
18-
There are multiple ways to install mdBook.
19-
20-
1. **Binaries**
21-
22-
Binaries are available for download [here][releases]. Make sure to put the
23-
path to the binary into your `PATH`.
24-
25-
2. **From Crates.io**
26-
27-
This requires at least [Rust] 1.46 and Cargo to be installed. Once you have installed
28-
Rust, type the following in the terminal:
29-
30-
```
31-
cargo install mdbook
32-
```
33-
34-
This will download and compile mdBook for you, the only thing left to do is
35-
to add the Cargo bin directory to your `PATH`.
36-
37-
**Note for automatic deployment**
38-
39-
If you are using a script to do automatic deployments, we recommend that
40-
you specify a semver version range for mdBook when you install it through
41-
your script!
42-
43-
This will constrain the server to install the latest **non-breaking**
44-
version of mdBook and will prevent your books from failing to build because
45-
we released a new version.
46-
47-
You can also disable default features to speed up compile time.
48-
49-
Example:
50-
51-
```
52-
cargo install mdbook --no-default-features --vers "^0.4.0"
53-
```
54-
55-
3. **From Git**
56-
57-
The version published to crates.io will ever so slightly be behind the
58-
version hosted here on GitHub. If you need the latest version you can build
59-
the git version of mdBook yourself. Cargo makes this ***super easy***!
60-
61-
```
62-
cargo install --git https://github.com/rust-lang/mdBook.git mdbook
63-
```
64-
65-
Again, make sure to add the Cargo bin directory to your `PATH`.
66-
67-
4. **For Contributions**
68-
69-
If you want to contribute to mdBook you will have to clone the repository on
70-
your local machine:
71-
72-
```
73-
git clone https://github.com/rust-lang/mdBook.git
74-
```
75-
76-
`cd` into `mdBook/` and run
77-
78-
```
79-
cargo build
80-
```
81-
82-
The resulting binary can be found in `mdBook/target/debug/` under the name
83-
`mdBook` or `mdBook.exe`.
84-
85-
86-
## Usage
87-
88-
mdBook is primarily used as a command line tool, even though it exposes
89-
all its functionality as a Rust crate for integration in other projects.
90-
91-
Here are the main commands you will want to run. For a more exhaustive
92-
explanation, check out the [User Guide].
93-
94-
- `mdbook init <directory>`
95-
96-
The init command will create a directory with the minimal boilerplate to
97-
start with. If the `<directory>` parameter is omitted, the current
98-
directory will be used.
99-
100-
```
101-
book-test/
102-
├── book
103-
└── src
104-
├── chapter_1.md
105-
└── SUMMARY.md
106-
```
107-
108-
`book` and `src` are both directories. `src` contains the markdown files
109-
that will be used to render the output to the `book` directory.
110-
111-
Please, take a look at the [CLI docs] for more information and some neat tricks.
112-
113-
- `mdbook build`
114-
115-
This is the command you will run to render your book, it reads the
116-
`SUMMARY.md` file to understand the structure of your book, takes the
117-
markdown files in the source directory as input and outputs static html
118-
pages that you can upload to a server.
119-
120-
- `mdbook watch`
121-
122-
When you run this command, mdbook will watch your markdown files to rebuild
123-
the book on every change. This avoids having to come back to the terminal
124-
to type `mdbook build` over and over again.
125-
126-
- `mdbook serve`
127-
128-
Does the same thing as `mdbook watch` but additionally serves the book at
129-
`http://localhost:3000` (port is changeable) and reloads the browser when a
130-
change occurs.
131-
132-
- `mdbook clean`
133-
134-
Delete directory in which generated book is located.
135-
136-
### 3rd Party Plugins
137-
138-
The way a book is loaded and rendered can be configured by the user via third
139-
party plugins. These plugins are just programs which will be invoked during the
140-
build process and are split into roughly two categories, *preprocessors* and
141-
*renderers*.
142-
143-
Preprocessors are used to transform a book before it is sent to a renderer.
144-
One example would be to replace all occurrences of
145-
`{{#include some_file.ext}}` with the contents of that file. Some existing
146-
preprocessors are:
147-
148-
- `index` - a built-in preprocessor (enabled by default) which will transform
149-
all `README.md` chapters to `index.md` so `foo/README.md` can be accessed via
150-
the url `foo/` when published to a browser
151-
- `links` - a built-in preprocessor (enabled by default) for expanding the
152-
`{{# playground}}` and `{{# include}}` helpers in a chapter.
153-
- [`katex`](https://github.com/lzanini/mdbook-katex) - a preprocessor rendering LaTex equations to HTML.
154-
155-
Renderers are given the final book so they can do something with it. This is
156-
typically used for, as the name suggests, rendering the document in a particular
157-
format, however there's nothing stopping a renderer from doing static analysis
158-
of a book in order to validate links or run tests. Some existing renderers are:
159-
160-
- `html` - the built-in renderer which will generate a HTML version of the book
161-
- `markdown` - the built-in renderer (disabled by default) which will run
162-
preprocessors then output the resulting Markdown. Useful for debugging
163-
preprocessors.
164-
- [`linkcheck`] - a backend which will check that all links are valid
165-
- [`epub`] - an experimental EPUB generator
166-
- [`man`] - a backend that generates manual pages from the book
167-
168-
> **Note for Developers:** Feel free to send us a PR if you've developed your
169-
> own plugin and want it mentioned here.
170-
171-
A preprocessor or renderer is enabled by installing the appropriate program and
172-
then mentioning it in the book's `book.toml` file.
173-
174-
```console
175-
$ cargo install mdbook-linkcheck
176-
$ edit book.toml && cat book.toml
177-
[book]
178-
title = "My Awesome Book"
179-
authors = ["Michael-F-Bryan"]
180-
181-
[output.html]
182-
183-
[output.linkcheck] # enable the "mdbook-linkcheck" renderer
184-
185-
$ mdbook build
186-
2018-10-20 13:57:51 [INFO] (mdbook::book): Book building has started
187-
2018-10-20 13:57:51 [INFO] (mdbook::book): Running the html backend
188-
2018-10-20 13:57:53 [INFO] (mdbook::book): Running the linkcheck backend
189-
```
190-
191-
For more information on the plugin system, consult the [User Guide].
192-
193-
### As a library
194-
195-
Aside from the command line interface, this crate can also be used as a
196-
library. This means that you could integrate it in an existing project, like a
197-
web-app for example. Since the command line interface is just a wrapper around
198-
the library functionality, when you use this crate as a library you have full
199-
access to all the functionality of the command line interface with an easy to
200-
use API and more!
201-
202-
See the [User Guide] and the [API docs] for more information.
203-
204-
## Contributions
205-
206-
Contributions are highly appreciated and encouraged! Don't hesitate to
207-
participate to discussions in the issues, propose new features and ask for
208-
help.
209-
210-
If you are just starting out with Rust, there are a series of issues that are
211-
tagged [E-Easy] and **we will gladly mentor you** so that you can successfully
212-
go through the process of fixing a bug or adding a new feature! Let us know if
213-
you need any help.
214-
215-
For more info about contributing, check out our [contribution guide] which helps
216-
you go through the build and contribution process!
217-
218-
There is also a [rendered version][master-docs] of the latest API docs
219-
available, for those hacking on `master`.
220-
12+
If you are interested in contributing to the development of mdBook, check out the [Contribution Guide].
22113

22214
## License
22315

22416
All the code in this repository is released under the ***Mozilla Public License v2.0***, for more information take a look at the [LICENSE] file.
22517

226-
22718
[User Guide]: https://rust-lang.github.io/mdBook/
228-
[API docs]: https://docs.rs/mdbook/*/mdbook/
229-
[E-Easy]: https://github.com/rust-lang/mdBook/issues?q=is%3Aopen+is%3Aissue+label%3AE-Easy
23019
[contribution guide]: https://github.com/rust-lang/mdBook/blob/master/CONTRIBUTING.md
23120
[LICENSE]: https://github.com/rust-lang/mdBook/blob/master/LICENSE
232-
[releases]: https://github.com/rust-lang/mdBook/releases
233-
[Rust]: https://www.rust-lang.org/
234-
[CLI docs]: http://rust-lang.github.io/mdBook/cli/init.html
235-
[master-docs]: http://rust-lang.github.io/mdBook/
236-
[`linkcheck`]: https://crates.io/crates/mdbook-linkcheck
237-
[`epub`]: https://crates.io/crates/mdbook-epub
238-
[`man`]: https://crates.io/crates/mdbook-man

‎guide/src/README.md

+25-17
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
11
# Introduction
22

3-
**mdBook** is a command line tool and Rust crate to create books with Markdown. The output resembles tools like Gitbook,
4-
and is ideal for creating product or API documentation, tutorials, course materials or anything that requires a clean,
5-
easily navigable and customizable presentation. mdBook is written in [Rust](https://www.rust-lang.org); its performance
6-
and simplicity made it ideal for use as a tool to publish directly to hosted websites such
7-
as [GitHub Pages](https://pages.github.com) via automation. This guide, in fact, serves as both the mdBook documentation
8-
and a fine example of what mdBook produces.
9-
10-
mdBook includes built in support for both preprocessing your Markdown and alternative renderers for producing formats
11-
other than HTML. These facilities also enable other functionality such as
12-
validation. [Searching](https://crates.io/search?q=mdbook&sort=relevance) Rust's [crates.io](https://crates.io) is a
13-
great way to discover more extensions.
14-
15-
## API Documentation
16-
17-
In addition to the above features, mdBook also has a Rust [API](https://docs.rs/mdbook/*/mdbook/). This allows you to
18-
write your own preprocessor or renderer, as well as incorporate mdBook features into other applications.
19-
The [For Developers](for_developers) section of this guide contains more information and some examples.
3+
**mdBook** is a command line tool to create books with Markdown.
4+
It is ideal for creating product or API documentation, tutorials, course materials or anything that requires a clean,
5+
easily navigable and customizable presentation.
6+
7+
* Lightweight [Markdown] syntax helps you focus more on your content
8+
* Integrated [search] support
9+
* Color [syntax highlighting] for code blocks for many different languages
10+
* [Theme] files allow customizing the formatting of the output
11+
* [Preprocessors] can provide extensions for custom syntax and modifying content
12+
* [Backends] can render the output to multiple formats
13+
* Written in [Rust] for speed, safety, and simplicity
14+
* Automated testing of [Rust code samples]
15+
16+
This guide is an example of what mdBook produces.
17+
mdBook is used by the Rust programming language project, and [The Rust Programming Language][trpl] book is another fine example of mdBook in action.
18+
19+
[Markdown]: format/markdown.md
20+
[search]: guide/reading.md#search
21+
[syntax highlighting]: format/theme/syntax-highlighting.md
22+
[theme]: format/theme/index.html
23+
[preprocessors]: format/configuration/preprocessors.md
24+
[backends]: format/configuration/renderers.md
25+
[Rust]: https://www.rust-lang.org/
26+
[trpl]: https://doc.rust-lang.org/book/
27+
[Rust code samples]: cli/test.md
2028

2129
## Contributing
2230

‎guide/src/SUMMARY.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
# Summary
22

3-
- [Introduction](README.md)
3+
[Introduction](README.md)
4+
5+
# User Guide
6+
7+
- [Installation](guide/installation.md)
8+
- [Reading Books](guide/reading.md)
9+
- [Creating a Book](guide/creating.md)
10+
11+
# Reference Guide
12+
413
- [Command Line Tool](cli/README.md)
514
- [init](cli/init.md)
615
- [build](cli/build.md)
716
- [watch](cli/watch.md)
817
- [serve](cli/serve.md)
918
- [test](cli/test.md)
1019
- [clean](cli/clean.md)
20+
- [completions](cli/completions.md)
1121
- [Format](format/README.md)
1222
- [SUMMARY.md](format/summary.md)
1323
- [Draft chapter]()

‎guide/src/cli/README.md

+12-53
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,14 @@
11
# Command Line Tool
22

3-
mdBook can be used either as a command line tool or a [Rust
4-
crate](https://crates.io/crates/mdbook). Let's focus on the command line tool
5-
capabilities first.
6-
7-
## Install From Binaries
8-
9-
Precompiled binaries are provided for major platforms on a best-effort basis.
10-
Visit [the releases page](https://github.com/rust-lang/mdBook/releases)
11-
to download the appropriate version for your platform.
12-
13-
## Install From Source
14-
15-
mdBook can also be installed by compiling the source code on your local machine.
16-
17-
### Pre-requisite
18-
19-
mdBook is written in **[Rust](https://www.rust-lang.org/)** and therefore needs
20-
to be compiled with **Cargo**. If you haven't already installed Rust, please go
21-
ahead and [install it](https://www.rust-lang.org/tools/install) now.
22-
23-
### Install Crates.io version
24-
25-
Installing mdBook is relatively easy if you already have Rust and Cargo
26-
installed. You just have to type this snippet in your terminal:
27-
28-
```bash
29-
cargo install mdbook
30-
```
31-
32-
This will fetch the source code for the latest release from
33-
[Crates.io](https://crates.io/) and compile it. You will have to add Cargo's
34-
`bin` directory to your `PATH`.
35-
36-
Run `mdbook help` in your terminal to verify if it works. Congratulations, you
37-
have installed mdBook!
38-
39-
40-
### Install Git version
41-
42-
The **[git version](https://github.com/rust-lang/mdBook)** contains all
43-
the latest bug-fixes and features, that will be released in the next version on
44-
**Crates.io**, if you can't wait until the next release. You can build the git
45-
version yourself. Open your terminal and navigate to the directory of you
46-
choice. We need to clone the git repository and then build it with Cargo.
47-
48-
```bash
49-
git clone --depth=1 https://github.com/rust-lang/mdBook.git
50-
cd mdBook
51-
cargo build --release
52-
```
53-
54-
The executable `mdbook` will be in the `./target/release` folder, this should be
55-
added to the path.
3+
The `mdbook` command-line tool is used to create and build books.
4+
After you have [installed](../guide/installation.md) `mdbook`, you can run the `mdbook help` command in your terminal to view the available commands.
5+
6+
This following sections provide in-depth information on the different commands available.
7+
8+
* [`mdbook init <directory>`](init.md) — Creates a new book with minimal boilerplate to start with.
9+
* [`mdbook build`](build.md) — Renders the book.
10+
* [`mdbook watch`](watch.md) — Rebuilds the book any time a source file changes.
11+
* [`mdbook serve`](serve.md) — Runs a web server to view the book, and rebuilds on changes.
12+
* [`mdbook test`](test.md) — Tests Rust code samples.
13+
* [`mdbook clean`](clean.md) — Deletes the rendered output.
14+
* [`mdbook completions`](completions.md) — Support for shell auto-completion.

‎guide/src/cli/completions.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# The completions command
2+
3+
The completions command is used to generate auto-completions for some common shells.
4+
This means when you type `mdbook` in your shell, you can then press your shell's auto-complete key (usually the Tab key) and it may display what the valid options are, or finish partial input.
5+
6+
The completions first need to be installed for your shell:
7+
8+
```bash
9+
mdbook completions bash > ~/.local/share/bash-completion/completions/mdbook
10+
```
11+
12+
The command prints a completion script for the given shell.
13+
Run `mdbook completions --help` for a list of supported shells.
14+
15+
Where to place the completions depend on which shell you are using and your operating system.
16+
Consult your shell's documentation for more information one where to place the script.

‎guide/src/continuous-integration.md

+98-131
Original file line numberDiff line numberDiff line change
@@ -1,154 +1,121 @@
11
# Running `mdbook` in Continuous Integration
22

3-
While the following examples use Travis CI, their principles should
4-
straightforwardly transfer to other continuous integration providers as well.
3+
There are a variety of services such as [GitHub Actions] or [GitLab CI/CD] which can be used to test and deploy your book automatically.
54

6-
## Ensuring Your Book Builds and Tests Pass
5+
The following provides some general guidelines on how to configure your service to run mdBook.
6+
Specific recipes can be found at the [Automated Deployment] wiki page.
77

8-
Here is a sample Travis CI `.travis.yml` configuration that ensures `mdbook
9-
build` and `mdbook test` run successfully. The key to fast CI turnaround times
10-
is caching `mdbook` installs, so that you aren't compiling `mdbook` on every CI
11-
run.
8+
[GitHub Actions]: https://docs.github.com/en/actions
9+
[GitLab CI/CD]: https://docs.gitlab.com/ee/ci/
10+
[Automated Deployment]: https://github.com/rust-lang/mdBook/wiki/Automated-Deployment
1211

13-
```yaml
14-
language: rust
15-
sudo: false
12+
## Installing mdBook
1613

17-
cache:
18-
- cargo
14+
There are several different strategies for installing mdBook.
15+
The particular method depends on your needs and preferences.
1916

20-
rust:
21-
- stable
17+
### Pre-compiled binaries
2218

23-
before_script:
24-
- (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update)
25-
- (test -x $HOME/.cargo/bin/mdbook || cargo install --vers "^0.3" mdbook)
26-
- cargo install-update -a
19+
Perhaps the easiest method is to use the pre-compiled binaries found on the [GitHub Releases page][releases].
20+
A simple approach would be to use the popular `curl` CLI tool to download the executable:
2721

28-
script:
29-
- mdbook build && mdbook test # In case of custom book path: mdbook build path/to/mybook && mdbook test path/to/mybook
22+
```sh
23+
mkdir bin
24+
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.14/mdbook-v0.4.14-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin
25+
bin/mdbook build
3026
```
3127

32-
## Deploying Your Book to GitHub Pages
28+
Some considerations for this approach:
3329

34-
Following these instructions will result in your book being published to GitHub
35-
pages after a successful CI run on your repository's `master` branch.
30+
* This is relatively fast, and does not necessarily require dealing with caching.
31+
* This does not require installing Rust.
32+
* Specifying a specific URL means you have to manually update your script to get a new version.
33+
This may be a benefit if you want to lock to a specific version.
34+
However, some users prefer to automatically get a newer version when they are published.
35+
* You are reliant on the GitHub CDN being available.
3636

37-
First, create a new GitHub "Personal Access Token" with the "public_repo"
38-
permissions (or "repo" for private repositories). Go to your repository's Travis
39-
CI settings page and add an environment variable named `GITHUB_TOKEN` that is
40-
marked secure and *not* shown in the logs.
37+
[releases]: https://github.com/rust-lang/mdBook/releases
4138

42-
Whilst still in your repository's settings page, navigate to Options and change the
43-
Source on GitHub pages to `gh-pages`.
39+
### Building from source
4440

45-
Then, append this snippet to your `.travis.yml` and update the path to the
46-
`book` directory:
41+
Building from source will require having Rust installed.
42+
Some services have Rust pre-installed, but if your service does not, you will need to add a step to install it.
4743

48-
```yaml
49-
deploy:
50-
provider: pages
51-
skip-cleanup: true
52-
github-token: $GITHUB_TOKEN
53-
local-dir: book # In case of custom book path: path/to/mybook/book
54-
keep-history: false
55-
on:
56-
branch: main
57-
```
44+
After Rust is installed, `cargo install` can be used to build and install mdBook.
45+
We recommend using a SemVer version specifier so that you get the latest **non-breaking** version of mdBook.
46+
For example:
5847

59-
That's it!
60-
61-
Note: Travis has a new [dplv2](https://blog.travis-ci.com/2019-08-27-deployment-tooling-dpl-v2-preview-release) configuration that is currently in beta. To use this new format, update your `.travis.yml` file to:
62-
63-
```yaml
64-
language: rust
65-
os: linux
66-
dist: xenial
67-
68-
cache:
69-
- cargo
70-
71-
rust:
72-
- stable
73-
74-
before_script:
75-
- (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update)
76-
- (test -x $HOME/.cargo/bin/mdbook || cargo install --vers "^0.3" mdbook)
77-
- cargo install-update -a
78-
79-
script:
80-
- mdbook build && mdbook test # In case of custom book path: mdbook build path/to/mybook && mdbook test path/to/mybook
81-
82-
deploy:
83-
provider: pages
84-
strategy: git
85-
edge: true
86-
cleanup: false
87-
github-token: $GITHUB_TOKEN
88-
local-dir: book # In case of custom book path: path/to/mybook/book
89-
keep-history: false
90-
on:
91-
branch: main
92-
target_branch: gh-pages
48+
```sh
49+
cargo install mdbook --no-default-features --features search --vers "^0.4" --locked
9350
```
9451

95-
### Deploying to GitHub Pages manually
96-
97-
If your CI doesn't support GitHub pages, or you're deploying somewhere else
98-
with integrations such as Github Pages:
99-
*note: you may want to use different tmp dirs*:
100-
101-
```console
102-
$> git worktree add /tmp/book gh-pages
103-
$> mdbook build
104-
$> rm -rf /tmp/book/* # this won't delete the .git directory
105-
$> cp -rp book/* /tmp/book/
106-
$> cd /tmp/book
107-
$> git add -A
108-
$> git commit 'new book message'
109-
$> git push origin gh-pages
110-
$> cd -
111-
```
52+
This includes several recommended options:
11253

113-
Or put this into a Makefile rule:
114-
115-
```makefile
116-
.PHONY: deploy
117-
deploy: book
118-
@echo "====> deploying to github"
119-
git worktree add /tmp/book gh-pages
120-
rm -rf /tmp/book/*
121-
cp -rp book/* /tmp/book/
122-
cd /tmp/book && \
123-
git add -A && \
124-
git commit -m "deployed on $(shell date) by ${USER}" && \
125-
git push origin gh-pages
126-
```
54+
* `--no-default-features` — Disables features like the HTTP server used by `mdbook serve` that is likely not needed on CI.
55+
This will speed up the build time significantly.
56+
* `--features search` — Disabling default features means you should then manually enable features that you want, such as the built-in [search] capability.
57+
* `--vers "^0.4"` — This will install the most recent version of the `0.4` series.
58+
However, versions after like `0.5.0` won't be installed, as they may break your build.
59+
Cargo will automatically upgrade mdBook if you have an older version already installed.
60+
* `--locked` — This will use the dependencies that were used when mdBook was released.
61+
Without `--locked`, it will use the latest version of all dependencies, which may include some fixes since the last release, but may also (rarely) cause build problems.
62+
63+
You will likely want to investigate caching options, as building mdBook can be somewhat slow.
64+
65+
[search]: guide/reading.md#search
66+
67+
## Running tests
68+
69+
You may want to run tests using [`mdbook test`] every time you push a change or create a pull request.
70+
This can be used to validate Rust code examples in the book.
71+
72+
This will require having Rust installed.
73+
Some services have Rust pre-installed, but if your service does not, you will need to add a step to install it.
74+
75+
Other than making sure the appropriate version of Rust is installed, there's not much more than just running `mdbook test` from the book directory.
76+
77+
You may also want to consider running other kinds of tests, like [mdbook-linkcheck] which will check for broken links.
78+
Or if you have your own style checks, spell checker, or any other tests it might be good to run them in CI.
79+
80+
[`mdbook test`]: cli/test.md
81+
[mdbook-linkcheck]: https://github.com/Michael-F-Bryan/mdbook-linkcheck#continuous-integration
12782

128-
## Deploying Your Book to GitLab Pages
129-
Inside your repository's project root, create a file named `.gitlab-ci.yml` with the following contents:
130-
```yml
131-
stages:
132-
- deploy
133-
134-
pages:
135-
stage: deploy
136-
image: rust
137-
variables:
138-
CARGO_HOME: $CI_PROJECT_DIR/cargo
139-
before_script:
140-
- export PATH="$PATH:$CARGO_HOME/bin"
141-
- mdbook --version || cargo install mdbook
142-
script:
143-
- mdbook build -d public
144-
rules:
145-
- if: '$CI_COMMIT_REF_NAME == "master"'
146-
artifacts:
147-
paths:
148-
- public
149-
cache:
150-
paths:
151-
- $CARGO_HOME/bin
83+
## Deploying
84+
85+
You may want to automatically deploy your book.
86+
Some may want to do this with every time a change is pushed, and others may want to only deploy when a specific release is tagged.
87+
88+
You'll also need to understand the specifics on how to push a change to your web service.
89+
For example, [GitHub Pages] just requires committing the output onto a specific git branch.
90+
Other services may require using something like SSH to connect to a remote server.
91+
92+
The basic outline is that you need to run `mdbook build` to generate the output, and then transfer the files (which are in the `book` directory) to the correct location.
93+
94+
You may then want to consider if you need to invalidate any caches on your web service.
95+
96+
See the [Automated Deployment] wiki page for examples of various different services.
97+
98+
[GitHub Pages]: https://docs.github.com/en/pages
99+
100+
### 404 handling
101+
102+
mdBook automatically generates a 404 page to be used for broken links.
103+
The default output is a file named `404.html` at the root of the book.
104+
Some services like [GitHub Pages] will automatically use this page for broken links.
105+
For other services, you may want to consider configuring the web server to use this page as it will provide the reader navigation to get back to the book.
106+
107+
If your book is not deployed at the root of the domain, then you should set the [`output.html.site-url`] setting so that the 404 page works correctly.
108+
It needs to know where the book is deployed in order to load the static files (like CSS) correctly.
109+
For example, this guide is deployed at <https://rust-lang.github.io/mdBook/>, and the `site-url` setting is configured like this:
110+
111+
```toml
112+
# book.toml
113+
[output.html]
114+
site-url = "/mdBook/"
152115
```
153116

154-
After you commit and push this new file, GitLab CI will run and your book will be available!
117+
You can customize the look of the 404 page by creating a file named `src/404.md` in your book.
118+
If you want to use a different filename, you can set [`output.html.input-404`] to a different filename.
119+
120+
[`output.html.site-url`]: format/configuration/renderers.md#html-renderer-options
121+
[`output.html.input-404`]: format/configuration/renderers.md#html-renderer-options

‎guide/src/for_developers/README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ The process of rendering a book project goes through several steps.
2424
exist
2525
- Load the book chapters into memory
2626
- Discover which preprocessors/backends should be used
27-
2. Run the preprocessors
28-
3. Call each backend in turn
27+
2. For each backend:
28+
1. Run all the preprocessors.
29+
2. Call the backend to render the processed result.
2930

3031

3132
## Using `mdbook` as a Library

‎guide/src/for_developers/backends.md

+6-49
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,17 @@ rendering process. This program is passed a JSON representation of the book and
55
configuration information via `stdin`. Once the backend receives this
66
information it is free to do whatever it wants.
77

8-
There are already several alternative backends on GitHub which can be used as a
9-
rough example of how this is accomplished in practice.
8+
See [Configuring Renderers](../format/configuration/renderers.md) for more information about using backends.
109

11-
- [mdbook-linkcheck] - a simple program for verifying the book doesn't contain
12-
any broken links
13-
- [mdbook-epub] - an EPUB renderer
14-
- [mdbook-test] - a program to run the book's contents through [rust-skeptic] to
15-
verify everything compiles and runs correctly (similar to `rustdoc --test`)
16-
- [mdbook-man] - generate manual pages from the book
10+
The community has developed several backends.
11+
See the [Third Party Plugins] wiki page for a list of available backends.
12+
13+
## Setting Up
1714

1815
This page will step you through creating your own alternative backend in the form
1916
of a simple word counting program. Although it will be written in Rust, there's
2017
no reason why it couldn't be accomplished using something like Python or Ruby.
2118

22-
23-
## Setting Up
24-
2519
First you'll want to create a new binary program and add `mdbook` as a
2620
dependency.
2721

@@ -330,39 +324,6 @@ generation or a warning).
330324
All environment variables are passed through to the backend, allowing you to use
331325
the usual `RUST_LOG` to control logging verbosity.
332326

333-
## Handling missing backends
334-
335-
If you enable a backend that isn't installed, the default behavior is to throw an error:
336-
337-
```text
338-
The command `mdbook-wordcount` wasn't found, is the "wordcount" backend installed?
339-
If you want to ignore this error when the "wordcount" backend is not installed,
340-
set `optional = true` in the `[output.wordcount]` section of the book.toml configuration file.
341-
```
342-
343-
This behavior can be changed by marking the backend as optional.
344-
345-
```diff
346-
[book]
347-
title = "mdBook Documentation"
348-
description = "Create book from markdown files. Like Gitbook but implemented in Rust"
349-
authors = ["Mathieu David", "Michael-F-Bryan"]
350-
351-
[output.html]
352-
353-
[output.wordcount]
354-
command = "python /path/to/wordcount.py"
355-
+ optional = true
356-
```
357-
358-
This demotes the error to a warning, and it will instead look like this:
359-
360-
```text
361-
The command was not found, but was marked as optional.
362-
Command: wordcount
363-
```
364-
365-
366327
## Wrapping Up
367328

368329
Although contrived, hopefully this example was enough to show how you'd create
@@ -375,11 +336,7 @@ as a good example of how it's done in real life, so feel free to skim through
375336
the source code or ask questions.
376337

377338

378-
[mdbook-linkcheck]: https://github.com/Michael-F-Bryan/mdbook-linkcheck
379-
[mdbook-epub]: https://github.com/Michael-F-Bryan/mdbook-epub
380-
[mdbook-test]: https://github.com/Michael-F-Bryan/mdbook-test
381-
[mdbook-man]: https://github.com/vv9k/mdbook-man
382-
[rust-skeptic]: https://github.com/budziq/rust-skeptic
339+
[Third Party Plugins]: https://github.com/rust-lang/mdBook/wiki/Third-party-plugins
383340
[`RenderContext`]: https://docs.rs/mdbook/*/mdbook/renderer/struct.RenderContext.html
384341
[`RenderContext::from_json()`]: https://docs.rs/mdbook/*/mdbook/renderer/struct.RenderContext.html#method.from_json
385342
[`semver`]: https://crates.io/crates/semver

‎guide/src/for_developers/preprocessors.md

+2-19
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,18 @@ book is loaded and before it gets rendered, allowing you to update and mutate
55
the book. Possible use cases are:
66

77
- Creating custom helpers like `\{{#include /path/to/file.md}}`
8-
- Updating links so `[some chapter](some_chapter.md)` is automatically changed
9-
to `[some chapter](some_chapter.html)` for the HTML renderer
108
- Substituting in latex-style expressions (`$$ \frac{1}{3} $$`) with their
119
mathjax equivalents
1210

11+
See [Configuring Preprocessors](../format/configuration/preprocessors.md) for more information about using preprocessors.
1312

1413
## Hooking Into MDBook
1514

1615
MDBook uses a fairly simple mechanism for discovering third party plugins.
17-
A new table is added to `book.toml` (e.g. `preprocessor.foo` for the `foo`
16+
A new table is added to `book.toml` (e.g. `[preprocessor.foo]` for the `foo`
1817
preprocessor) and then `mdbook` will try to invoke the `mdbook-foo` program as
1918
part of the build process.
2019

21-
A preprocessor can be hard-coded to specify which backend(s) it should be run
22-
for with the `preprocessor.foo.renderer` key. For example, it doesn't make sense for
23-
[MathJax](../format/mathjax.md) to be used for non-HTML renderers.
24-
25-
```toml
26-
[book]
27-
title = "My Book"
28-
authors = ["Michael-F-Bryan"]
29-
30-
[preprocessor.foo]
31-
# The command can also be specified manually
32-
command = "python3 /path/to/foo.py"
33-
# Only run the `foo` preprocessor for the HTML and EPUB renderer
34-
renderer = ["html", "epub"]
35-
```
36-
3720
Once the preprocessor has been defined and the build process starts, mdBook executes the command defined in the `preprocessor.foo.command` key twice.
3821
The first time it runs the preprocessor to determine if it supports the given renderer.
3922
mdBook passes two arguments to the process: the first argument is the string `supports` and the second argument is the renderer name.

‎guide/src/format/configuration/general.md

+13
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ language = "en"
6262
Options for the Rust language, relevant to running tests and playground
6363
integration.
6464

65+
```toml
66+
[rust]
67+
edition = "2015" # the default edition for code blocks
68+
```
69+
6570
- **edition**: Rust edition to use by default for the code snippets. Default
6671
is "2015". Individual code blocks can be controlled with the `edition2015`,
6772
`edition2018` or `edition2021` annotations, such as:
@@ -77,8 +82,16 @@ integration.
7782

7883
This controls the build process of your book.
7984

85+
```toml
86+
[build]
87+
build-dir = "book" # the directory where the output is placed
88+
create-missing = true # whether or not to create missing pages
89+
use-default-preprocessors = true # use the default preprocessors
90+
```
91+
8092
- **build-dir:** The directory to put the rendered book in. By default this is
8193
`book/` in the book's root directory.
94+
This can overridden with the `--dest-dir` CLI option.
8295
- **create-missing:** By default, any missing files specified in `SUMMARY.md`
8396
will be created when the book is built (i.e. `create-missing = true`). If this
8497
is `false` then the build process will instead exit with an error if any files

‎guide/src/format/configuration/preprocessors.md

+31-24
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,58 @@
11
# Configuring Preprocessors
22

3-
The following preprocessors are available and included by default:
3+
Preprocessors are extensions that can modify the raw Markdown source before it gets sent to the renderer.
44

5-
- `links`: Expand the `{{ #playground }}`, `{{ #include }}`, and `{{ #rustdoc_include }}` handlebars
5+
The following preprocessors are built-in and included by default:
6+
7+
- `links`: Expands the `{{ #playground }}`, `{{ #include }}`, and `{{ #rustdoc_include }}` handlebars
68
helpers in a chapter to include the contents of a file.
9+
See [Including files] for more.
710
- `index`: Convert all chapter files named `README.md` into `index.md`. That is
811
to say, all `README.md` would be rendered to an index file `index.html` in the
912
rendered book.
1013

14+
The built-in preprocessors can be disabled with the [`build.use-default-preprocessors`] config option.
1115

12-
**book.toml**
13-
```toml
14-
[build]
15-
build-dir = "build"
16-
create-missing = false
16+
The community has developed several preprocessors.
17+
See the [Third Party Plugins] wiki page for a list of available preprocessors.
1718

18-
[preprocessor.links]
19+
For information on how to create a new preprocessor, see the [Preprocessors for Developers] chapter.
1920

20-
[preprocessor.index]
21-
```
21+
[Including files]: ../mdbook.md#including-files
22+
[`build.use-default-preprocessors`]: general.md#build-options
23+
[Third Party Plugins]: https://github.com/rust-lang/mdBook/wiki/Third-party-plugins
24+
[Preprocessors for Developers]: ../../for_developers/preprocessors.md
2225

23-
### Custom Preprocessor Configuration
26+
## Custom Preprocessor Configuration
2427

25-
Like renderers, preprocessor will need to be given its own table (e.g.
26-
`[preprocessor.mathjax]`). In the section, you may then pass extra
27-
configuration to the preprocessor by adding key-value pairs to the table.
28+
Preprocessors can be added by including a `preprocessor` table in `book.toml` with the name of the preprocessor.
29+
For example, if you have a preprocessor called `mdbook-example`, then you can include it with:
2830

29-
For example
31+
```toml
32+
[preprocessor.example]
33+
```
34+
35+
With this table, mdBook will execute the `mdbook-example` preprocessor.
36+
37+
This table can include additional key-value pairs that are specific to the preprocessor.
38+
For example, if our example prepocessor needed some extra configuration options:
3039

3140
```toml
32-
[preprocessor.links]
33-
# set the renderers this preprocessor will run for
34-
renderers = ["html"]
35-
some_extra_feature = true
41+
[preprocessor.example]
42+
some-extra-feature = true
3643
```
3744

38-
#### Locking a Preprocessor dependency to a renderer
45+
## Locking a Preprocessor dependency to a renderer
3946

4047
You can explicitly specify that a preprocessor should run for a renderer by
4148
binding the two together.
4249

4350
```toml
44-
[preprocessor.mathjax]
45-
renderers = ["html"] # mathjax only makes sense with the HTML renderer
51+
[preprocessor.example]
52+
renderers = ["html"] # example preprocessor only runs with the HTML renderer
4653
```
4754

48-
### Provide Your Own Command
55+
## Provide Your Own Command
4956

5057
By default when you add a `[preprocessor.foo]` table to your `book.toml` file,
5158
`mdbook` will try to invoke the `mdbook-foo` executable. If you want to use a
@@ -57,7 +64,7 @@ be overridden by adding a `command` field.
5764
command = "python random.py"
5865
```
5966

60-
### Require A Certain Order
67+
## Require A Certain Order
6168

6269
The order in which preprocessors are run can be controlled with the `before` and `after` fields.
6370
For example, suppose you want your `linenos` preprocessor to process lines that may have been `{{#include}}`d; then you want it to run after the built-in `links` preprocessor, which you can require using either the `before` or `after` field:

‎guide/src/format/configuration/renderers.md

+175-88
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,115 @@
11
# Configuring Renderers
22

3-
### HTML renderer options
3+
Renderers (also called "backends") are responsible for creating the output of the book.
44

5-
The HTML renderer has a couple of options as well. All the options for the
6-
renderer need to be specified under the TOML table `[output.html]`.
5+
The following backends are built-in:
6+
7+
* [`html`](#html-renderer-options) — This renders the book to HTML.
8+
This is enabled by default if no other `[output]` tables are defined in `book.toml`.
9+
* [`markdown`](#markdown-renderer) — This outputs the book as markdown after running the preprocessors.
10+
This is useful for debugging preprocessors.
11+
12+
The community has developed several backends.
13+
See the [Third Party Plugins] wiki page for a list of available backends.
14+
15+
For information on how to create a new backend, see the [Backends for Developers] chapter.
16+
17+
[Third Party Plugins]: https://github.com/rust-lang/mdBook/wiki/Third-party-plugins
18+
[Backends for Developers]: ../../for_developers/backends.md
19+
20+
## Output tables
21+
22+
Backends can be added by including a `output` table in `book.toml` with the name of the backend.
23+
For example, if you have a backend called `mdbook-wordcount`, then you can include it with:
24+
25+
```toml
26+
[output.wordcount]
27+
```
28+
29+
With this table, mdBook will execute the `mdbook-wordcount` backend.
30+
31+
This table can include additional key-value pairs that are specific to the backend.
32+
For example, if our example backend needed some extra configuration options:
33+
34+
```toml
35+
[output.wordcount]
36+
ignores = ["Example Chapter"]
37+
```
38+
39+
If you define any `[output]` tables, then the `html` backend is not enabled by default.
40+
If you want to keep the `html` backend running, then just include it in the `book.toml` file.
41+
For example:
42+
43+
```toml
44+
[book]
45+
title = "My Awesome Book"
46+
47+
[output.wordcount]
48+
49+
[output.html]
50+
```
51+
52+
If more than one `output` table is included, this changes the behavior for the layout of the output directory.
53+
If there is only one backend, then it places its output directly in the `book` directory (see [`build.build-dir`] to override this location).
54+
If there is more than one backend, then each backend is placed in a separate directory underneath `book`.
55+
For example, the above would have directories `book/html` and `book/wordcount`.
56+
57+
[`build.build-dir`]: general.md#build-options
58+
59+
### Custom backend commands
60+
61+
By default when you add an `[output.foo]` table to your `book.toml` file,
62+
`mdbook` will try to invoke the `mdbook-foo` executable.
63+
If you want to use a different program name or pass in command-line arguments,
64+
this behaviour can be overridden by adding a `command` field.
65+
66+
```toml
67+
[output.random]
68+
command = "python random.py"
69+
```
70+
71+
### Optional backends
72+
73+
If you enable a backend that isn't installed, the default behavior is to throw an error.
74+
This behavior can be changed by marking the backend as optional:
75+
76+
```toml
77+
[output.wordcount]
78+
optional = true
79+
```
80+
81+
This demotes the error to a warning.
82+
83+
84+
## HTML renderer options
85+
86+
The HTML renderer has a variety of options detailed below.
87+
They should be specified in the `[output.html]` table of the `book.toml` file.
88+
89+
```toml
90+
# Example book.toml file with all output options.
91+
[book]
92+
title = "Example book"
93+
authors = ["John Doe", "Jane Doe"]
94+
description = "The example book covers examples."
95+
96+
[output.html]
97+
theme = "my-theme"
98+
default-theme = "light"
99+
preferred-dark-theme = "navy"
100+
curly-quotes = true
101+
mathjax-support = false
102+
copy-fonts = true
103+
additional-css = ["custom.css", "custom2.css"]
104+
additional-js = ["custom.js"]
105+
no-section-label = false
106+
git-repository-url = "https://github.com/rust-lang/mdBook"
107+
git-repository-icon = "fa-github"
108+
edit-url-template = "https://github.com/rust-lang/mdBook/edit/master/guide/{path}"
109+
site-url = "/example-book/"
110+
cname = "myproject.rs"
111+
input-404 = "not-found.md"
112+
```
7113

8114
The following configuration options are available:
9115

@@ -30,34 +136,22 @@ The following configuration options are available:
30136
- **additional-js:** If you need to add some behaviour to your book without
31137
removing the current behaviour, you can specify a set of JavaScript files that
32138
will be loaded alongside the default one.
33-
- **print:** A subtable for configuration print settings. mdBook by default adds
34-
support for printing out the book as a single page. This is accessed using the
35-
print icon on the top right of the book.
36-
- **no-section-label:** mdBook by defaults adds section label in table of
139+
- **no-section-label:** mdBook by defaults adds numeric section labels in the table of
37140
contents column. For example, "1.", "2.1". Set this option to true to disable
38141
those labels. Defaults to `false`.
39-
- **fold:** A subtable for configuring sidebar section-folding behavior.
40-
- **playground:** A subtable for configuring various playground settings.
41-
- **search:** A subtable for configuring the in-browser search functionality.
42-
mdBook must be compiled with the `search` feature enabled (on by default).
43142
- **git-repository-url:** A url to the git repository for the book. If provided
44143
an icon link will be output in the menu bar of the book.
45144
- **git-repository-icon:** The FontAwesome icon class to use for the git
46-
repository link. Defaults to `fa-github`.
145+
repository link. Defaults to `fa-github` which looks like <i class="fa fa-github"></i>.
146+
If you are not using GitHub, another option to consider is `fa-code-fork` which looks like <i class="fa fa-code-fork"></i>.
47147
- **edit-url-template:** Edit url template, when provided shows a
48-
"Suggest an edit" button for directly jumping to editing the currently
148+
"Suggest an edit" button (which looks like <i class="fa fa-edit"></i>) for directly jumping to editing the currently
49149
viewed page. For e.g. GitHub projects set this to
50150
`https://github.com/<owner>/<repo>/edit/master/{path}` or for
51151
Bitbucket projects set it to
52152
`https://bitbucket.org/<owner>/<repo>/src/master/{path}?mode=edit`
53153
where {path} will be replaced with the full path of the file in the
54154
repository.
55-
- **redirect:** A subtable used for generating redirects when a page is moved.
56-
The table contains key-value pairs where the key is where the redirect file
57-
needs to be created, as an absolute path from the build directory, (e.g.
58-
`/appendices/bibliography.html`). The value can be any valid URI the
59-
browser should navigate to (e.g. `https://rust-lang.org/`,
60-
`/overview.html`, or `../bibliography.html`).
61155
- **input-404:** The name of the markdown file used for missing files.
62156
The corresponding output file will be the same, with the extension replaced with `html`.
63157
Defaults to `404.md`.
@@ -71,19 +165,47 @@ The following configuration options are available:
71165

72166
[custom domain]: https://docs.github.com/en/github/working-with-github-pages/managing-a-custom-domain-for-your-github-pages-site
73167

74-
Available configuration options for the `[output.html.print]` table:
168+
### `[output.html.print]`
169+
170+
The `[output.html.print]` table provides options for controlling the printable output.
171+
By default, mdBook will include an icon on the top right of the book (which looks like <i class="fa fa-print"></i>) that will print the book as a single page.
172+
173+
```toml
174+
[output.html.print]
175+
enable = true # include support for printable output
176+
```
75177

76178
- **enable:** Enable print support. When `false`, all print support will not be
77179
rendered. Defaults to `true`.
78180

79-
Available configuration options for the `[output.html.fold]` table:
181+
### `[output.html.fold]`
182+
183+
The `[output.html.fold]` table provides options for controlling folding of the chapter listing in the navigation sidebar.
184+
185+
```toml
186+
[output.html.fold]
187+
enable = false # whether or not to enable section folding
188+
level = 0 # the depth to start folding
189+
```
80190

81191
- **enable:** Enable section-folding. When off, all folds are open.
82192
Defaults to `false`.
83193
- **level:** The higher the more folded regions are open. When level is 0, all
84194
folds are closed. Defaults to `0`.
85195

86-
Available configuration options for the `[output.html.playground]` table:
196+
### `[output.html.playground]`
197+
198+
The `[output.html.playground]` table provides options for controlling Rust sample code blocks, and their integration with the [Rust Playground].
199+
200+
[Rust Playground]: https://play.rust-lang.org/
201+
202+
```toml
203+
[output.html.playground]
204+
editable = false # allows editing the source code
205+
copyable = true # include the copy button for copying code snippets
206+
copy-js = true # includes the JavaScript for the code editor
207+
line-numbers = false # displays line numbers for editable code
208+
```
87209

88210
- **editable:** Allow editing the source code. Defaults to `false`.
89211
- **copyable:** Display the copy button on code snippets. Defaults to `true`.
@@ -93,7 +215,26 @@ Available configuration options for the `[output.html.playground]` table:
93215

94216
[Ace]: https://ace.c9.io/
95217

96-
Available configuration options for the `[output.html.search]` table:
218+
### `[output.html.search]`
219+
220+
The `[output.html.search]` table provides options for controlling the built-in text [search].
221+
mdBook must be compiled with the `search` feature enabled (on by default).
222+
223+
[search]: ../../guide/reading.md#search
224+
225+
```toml
226+
[output.html.search]
227+
enable = true # enables the search feature
228+
limit-results = 30 # maximum number of search results
229+
teaser-word-count = 30 # number of words used for a search result teaser
230+
use-boolean-and = true # multiple search terms must all match
231+
boost-title = 2 # ranking boost factor for matches in headers
232+
boost-hierarchy = 1 # ranking boost factor for matches in page names
233+
boost-paragraph = 1 # ranking boost factor for matches in text
234+
expand = true # partial words will match longer terms
235+
heading-split-level = 3 # link results to heading levels
236+
copy-js = true # include Javascript code for search
237+
```
97238

98239
- **enable:** Enables the search feature. Defaults to `true`.
99240
- **limit-results:** The maximum number of search results. Defaults to `30`.
@@ -116,61 +257,24 @@ Available configuration options for the `[output.html.search]` table:
116257
- **copy-js:** Copy JavaScript files for the search implementation to the output
117258
directory. Defaults to `true`.
118259

119-
This shows all available HTML output options in the **book.toml**:
260+
### `[output.html.redirect]`
120261

121-
```toml
122-
[book]
123-
title = "Example book"
124-
authors = ["John Doe", "Jane Doe"]
125-
description = "The example book covers examples."
126-
127-
[output.html]
128-
theme = "my-theme"
129-
default-theme = "light"
130-
preferred-dark-theme = "navy"
131-
curly-quotes = true
132-
mathjax-support = false
133-
copy-fonts = true
134-
additional-css = ["custom.css", "custom2.css"]
135-
additional-js = ["custom.js"]
136-
no-section-label = false
137-
git-repository-url = "https://github.com/rust-lang/mdBook"
138-
git-repository-icon = "fa-github"
139-
edit-url-template = "https://github.com/rust-lang/mdBook/edit/master/guide/{path}"
140-
site-url = "/example-book/"
141-
cname = "myproject.rs"
142-
input-404 = "not-found.md"
143-
144-
[output.html.print]
145-
enable = true
146-
147-
[output.html.fold]
148-
enable = false
149-
level = 0
150-
151-
[output.html.playground]
152-
editable = false
153-
copy-js = true
154-
line-numbers = false
155-
156-
[output.html.search]
157-
enable = true
158-
limit-results = 30
159-
teaser-word-count = 30
160-
use-boolean-and = true
161-
boost-title = 2
162-
boost-hierarchy = 1
163-
boost-paragraph = 1
164-
expand = true
165-
heading-split-level = 3
166-
copy-js = true
262+
The `[output.html.redirect]` table provides a way to add redirects.
263+
This is useful when you move, rename, or remove a page to ensure that links to the old URL will go to the new location.
167264

265+
```toml
168266
[output.html.redirect]
169267
"/appendices/bibliography.html" = "https://rustc-dev-guide.rust-lang.org/appendix/bibliography.html"
170268
"/other-installation-methods.html" = "../infra/other-installation-methods.html"
171269
```
172270

173-
### Markdown Renderer
271+
The table contains key-value pairs where the key is where the redirect file needs to be created, as an absolute path from the build directory, (e.g. `/appendices/bibliography.html`).
272+
The value can be any valid URI the browser should navigate to (e.g. `https://rust-lang.org/`, `/overview.html`, or `../bibliography.html`).
273+
274+
This will generate an HTML page which will automatically redirect to the given location.
275+
Note that the source location does not support `#` anchor redirects.
276+
277+
## Markdown Renderer
174278

175279
The Markdown renderer will run preprocessors and then output the resulting
176280
Markdown. This is mostly useful for debugging preprocessors, especially in
@@ -189,20 +293,3 @@ only whether it is enabled or disabled.
189293

190294
See [the preprocessors documentation](preprocessors.md) for how to
191295
specify which preprocessors should run before the Markdown renderer.
192-
193-
### Custom Renderers
194-
195-
A custom renderer can be enabled by adding a `[output.foo]` table to your
196-
`book.toml`. Similar to [preprocessors](preprocessors.md) this will
197-
instruct `mdbook` to pass a representation of the book to `mdbook-foo` for
198-
rendering. See the [alternative backends] chapter for more detail.
199-
200-
The custom renderer has access to all the fields within its table (i.e.
201-
anything under `[output.foo]`). mdBook checks for two common fields:
202-
203-
- **command:** The command to execute for this custom renderer. Defaults to
204-
the name of the renderer with the `mdbook-` prefix (such as `mdbook-foo`).
205-
- **optional:** If `true`, then the command will be ignored if it is not
206-
installed, otherwise mdBook will fail with an error. Defaults to `false`.
207-
208-
[alternative backends]: ../../for_developers/backends.md

‎guide/src/format/markdown.md

+118-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Markdown
22

3-
mdBook's [parser](https://github.com/raphlinus/pulldown-cmark) adheres to the [CommonMark](https://commonmark.org/)
4-
specification. You can take a quick [tutorial](https://commonmark.org/help/tutorial/),
3+
mdBook's [parser](https://github.com/raphlinus/pulldown-cmark) adheres to the [CommonMark](https://commonmark.org/) specification with some extensions described below.
4+
You can take a quick [tutorial](https://commonmark.org/help/tutorial/),
55
or [try out](https://spec.commonmark.org/dingus/) CommonMark in real time. A complete Markdown overview is out of scope for
66
this documentation, but below is a high level overview of some of the basics. For a more in-depth experience, check out the
77
[Markdown Guide](https://www.markdownguide.org).
@@ -84,6 +84,20 @@ Read about [mdBook](mdBook.md).
8484

8585
A bare url: <https://www.rust-lang.org>.
8686

87+
----
88+
89+
Relative links that end with `.md` will be converted to the `.html` extension.
90+
It is recommended to use `.md` links when possible.
91+
This is useful when viewing the Markdown file outside of mdBook, for example on GitHub or GitLab which render Markdown automatically.
92+
93+
Links to `README.md` will be converted to `index.html`.
94+
This is done since some services like GitHub render README files automatically, but web servers typically expect the root file to be called `index.html`.
95+
96+
You can link to individual headings with `#` fragments.
97+
For example, `mdbook.md#text-and-paragraphs` would link to the [Text and Paragraphs](#text-and-paragraphs) section above.
98+
The ID is created by transforming the heading such as converting to lowercase and replacing spaces with dashes.
99+
You can click on any heading and look at the URL in your browser to see what the fragment looks like.
100+
87101
## Images
88102

89103
Including images is simply a matter of including a link to them, much like in the _Links_ section above. The following markdown
@@ -103,5 +117,106 @@ Which, of course displays the image like so:
103117

104118
![The Rust Logo](images/rust-logo-blk.svg)
105119

120+
## Extensions
121+
122+
mdBook has several extensions beyond the standard CommonMark specification.
123+
124+
### Strikethrough
125+
126+
Text may be rendered with a horizontal line through the center by wrapping the
127+
text with two tilde characters on each side:
128+
129+
```text
130+
An example of ~~strikethrough text~~.
131+
```
132+
133+
This example will render as:
134+
135+
> An example of ~~strikethrough text~~.
136+
137+
This follows the [GitHub Strikethrough extension][strikethrough].
138+
139+
### Footnotes
140+
141+
A footnote generates a small numbered link in the text which when clicked
142+
takes the reader to the footnote text at the bottom of the item. The footnote
143+
label is written similarly to a link reference with a caret at the front. The
144+
footnote text is written like a link reference definition, with the text
145+
following the label. Example:
146+
147+
```text
148+
This is an example of a footnote[^note].
149+
150+
[^note]: This text is the contents of the footnote, which will be rendered
151+
towards the bottom.
152+
```
153+
154+
This example will render as:
155+
156+
> This is an example of a footnote[^note].
157+
>
158+
> [^note]: This text is the contents of the footnote, which will be rendered
159+
> towards the bottom.
160+
161+
The footnotes are automatically numbered based on the order the footnotes are
162+
written.
163+
164+
### Tables
165+
166+
Tables can be written using pipes and dashes to draw the rows and columns of
167+
the table. These will be translated to HTML table matching the shape. Example:
168+
169+
```text
170+
| Header1 | Header2 |
171+
|---------|---------|
172+
| abc | def |
173+
```
174+
175+
This example will render similarly to this:
176+
177+
| Header1 | Header2 |
178+
|---------|---------|
179+
| abc | def |
180+
181+
See the specification for the [GitHub Tables extension][tables] for more
182+
details on the exact syntax supported.
183+
184+
### Task lists
185+
186+
Task lists can be used as a checklist of items that have been completed.
187+
Example:
188+
189+
```md
190+
- [x] Complete task
191+
- [ ] Incomplete task
192+
```
193+
194+
This will render as:
195+
196+
> - [x] Complete task
197+
> - [ ] Incomplete task
198+
199+
See the specification for the [task list extension] for more details.
200+
201+
### Smart punctuation
202+
203+
Some ASCII punctuation sequences will be automatically turned into fancy Unicode
204+
characters:
205+
206+
| ASCII sequence | Unicode |
207+
|----------------|---------|
208+
| `--` ||
209+
| `---` ||
210+
| `...` ||
211+
| `"` | “ or ”, depending on context |
212+
| `'` | ‘ or ’, depending on context |
213+
214+
So, no need to manually enter those Unicode characters!
215+
216+
This feature is disabled by default.
217+
To enable it, see the [`output.html.curly-quotes`] config option.
106218

107-
See the [Markdown Guide Basic Syntax](https://www.markdownguide.org/basic-syntax/) document for more.
219+
[strikethrough]: https://github.github.com/gfm/#strikethrough-extension-
220+
[tables]: https://github.github.com/gfm/#tables-extension-
221+
[task list extension]: https://github.github.com/gfm/#task-list-items-extension-
222+
[`output.html.curly-quotes`]: configuration/renderers.md#html-renderer-options

‎guide/src/format/mdbook.md

+66
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
There is a feature in mdBook that lets you hide code lines by prepending them
66
with a `#` [like you would with Rustdoc][rustdoc-hide].
7+
This currently only works with Rust language code blocks.
78

89
[rustdoc-hide]: https://doc.rust-lang.org/stable/rustdoc/documentation-tests.html#hiding-portions-of-the-example
910

@@ -27,6 +28,60 @@ Will render as
2728
# }
2829
```
2930

31+
The code block has an eyeball icon (<i class="fa fa-eye"></i>) which will toggle the visibility of the hidden lines.
32+
33+
## Rust Playground
34+
35+
Rust language code blocks will automatically get a play button (<i class="fa fa-play"></i>) which will execute the code and display the output just below the code block.
36+
This works by sending the code to the [Rust Playground].
37+
38+
```rust
39+
println!("Hello, World!");
40+
```
41+
42+
If there is no `main` function, then the code is automatically wrapped inside one.
43+
44+
If you wish to disable the play button, you can include the `noplayground` option on the code block like this:
45+
46+
~~~markdown
47+
```rust,noplayground
48+
let mut name = String::new();
49+
std::io::stdin().read_line(&mut name).expect("failed to read line");
50+
println!("Hello {}!", name);
51+
```
52+
~~~
53+
54+
## Rust code block attributes
55+
56+
Additional attributes can be included in Rust code blocks with comma, space, or tab-separated terms just after the language term. For example:
57+
58+
~~~markdown
59+
```rust,ignore
60+
# This example won't be tested.
61+
panic!("oops!");
62+
```
63+
~~~
64+
65+
These are particularly important when using [`mdbook test`] to test Rust examples.
66+
These use the same attributes as [rustdoc attributes], with a few additions:
67+
68+
* `editable` — Enables the [editor].
69+
* `noplayground` — Removes the play button, but will still be tested.
70+
* `mdbook-runnable` — Forces the play button to be displayed.
71+
This is intended to be combined with the `ignore` attribute for examples that should not be tested, but you want to allow the reader to run.
72+
* `ignore` — Will not be tested and no play button is shown, but it is still highlighted as Rust syntax.
73+
* `should_panic` — When executed, it should produce a panic.
74+
* `no_run` — The code is compiled when tested, but it is not run.
75+
The play button is also not shown.
76+
* `compile_fail` — The code should fail to compile.
77+
* `edition2015`, `edition2018`, `edition2021` — Forces the use of a specific Rust edition.
78+
See [`rust.edition`] to set this globally.
79+
80+
[`mdbook test`]: ../cli/test.md
81+
[rustdoc attributes]: https://doc.rust-lang.org/rustdoc/documentation-tests.html#attributes
82+
[editor]: theme/editor.md
83+
[`rust.edition`]: configuration/general.md#rust-options
84+
3085
## Including files
3186

3287
With the following syntax, you can include files into your book:
@@ -191,6 +246,17 @@ Here is what a rendered code snippet looks like:
191246

192247
{{#playground example.rs}}
193248

249+
Any additional values passed after the filename will be included as attributes of the code block.
250+
For example `\{{#playground example.rs editable}}` will create the code block like the following:
251+
252+
~~~markdown
253+
```rust,editable
254+
# Contents of example.rs here.
255+
```
256+
~~~
257+
258+
And the `editable` attribute will enable the [editor] as described at [Rust code block attributes](#rust-code-block-attributes).
259+
194260
[Rust Playground]: https://play.rust-lang.org/
195261

196262
## Controlling page \<title\>

‎guide/src/format/theme/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ template and only add / modify what you need. You can copy the default theme
3838
into your source directory automatically by using `mdbook init --theme` and just
3939
remove the files you don't want to override.
4040

41+
`mdbook init --theme` will not create every file listed above.
42+
Some files, such as `head.hbs`, do not have built-in equivalents.
43+
Just create the file if you need it.
44+
4145
If you completely replace all built-in themes, be sure to also set
4246
[`output.html.preferred-dark-theme`] in the config, which defaults to the
4347
built-in `navy` theme.

‎guide/src/format/theme/editor.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ editable = true
1212
To make a specific block available for editing, the attribute `editable` needs
1313
to be added to it:
1414

15-
<pre><code class="language-markdown">```rust,editable
15+
~~~markdown
16+
```rust,editable
1617
fn main() {
1718
let number = 5;
1819
print!("{}", number);
1920
}
20-
```</code></pre>
21+
```
22+
~~~
2123

2224
The above will result in this editable playground:
2325

‎guide/src/guide/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# User Guide
2+
3+
This user guide provides an introduction to basic concepts of using mdBook.
4+
5+
- [Installation](installation.md)
6+
- [Reading Books](reading.md)
7+
- [Creating a Book](creating.md)

‎guide/src/guide/creating.md

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Creating a Book
2+
3+
Once you have the `mdbook` CLI tool installed, you can use it to create and render a book.
4+
5+
## Initializing a book
6+
7+
The `mdbook init` command will create a new directory containing an empty book for you to get started.
8+
Give it the name of the directory that you want to create:
9+
10+
```sh
11+
mdbook init my-first-book
12+
```
13+
14+
It will ask a few questions before generating the book.
15+
After answering the questions, you can change the current directory into the new book:
16+
17+
```sh
18+
cd my-first-book
19+
```
20+
21+
There are several ways to render a book, but one of the easiest methods is to use the `serve` command, which will build your book and start a local webserver:
22+
23+
```sh
24+
mdbook serve --open
25+
```
26+
27+
The `--open` option will open your default web browser to view your new book.
28+
You can leave the server running even while you edit the content of the book, and `mdbook` will automatically rebuild the output *and* automatically refresh your web browser.
29+
30+
Check out the [CLI Guide](../cli/index.html) for more information about other `mdbook` commands and CLI options.
31+
32+
## Anatomy of a book
33+
34+
A book is built from several files which define the settings and layout of the book.
35+
36+
### `book.toml`
37+
38+
In the root of your book, there is a `book.toml` file which contains settings for describing how to build your book.
39+
This is written in the [TOML markup language](https://toml.io/).
40+
The default settings are usually good enough to get you started.
41+
When you are interested in exploring more features and options that mdBook provides, check out the [Configuration chapter](../format/configuration/index.html) for more details.
42+
43+
A very basic `book.toml` can be as simple as this:
44+
45+
```toml
46+
[book]
47+
title = "My First Book"
48+
```
49+
50+
### `SUMMARY.md`
51+
52+
The next major part of a book is the summary file located at `src/SUMMARY.md`.
53+
This file contains a list of all the chapters in the book.
54+
Before a chapter can be viewed, it must be added to this list.
55+
56+
Here's a basic summary file with a few chapters:
57+
58+
```md
59+
# Summary
60+
61+
[Introduction](README.md)
62+
63+
- [My First Chapter](my-first-chapter.md)
64+
- [Nested example](nested/README.md)
65+
- [Sub-chapter](nested/sub-chapter.md)
66+
```
67+
68+
Try opening up `src/SUMMARY.md` in your editor and adding a few chapters.
69+
If any of the chapter files do not exist, `mdbook` will automatically create them for you.
70+
71+
For more details on other formatting options for the summary file, check out the [Summary chapter](../format/summary.md).
72+
73+
### Source files
74+
75+
The content of your book is all contained in the `src` directory.
76+
Each chapter is a separate Markdown file.
77+
Typically, each chapter starts with a level 1 heading with the title of the chapter.
78+
79+
```md
80+
# My First Chapter
81+
82+
Fill out your content here.
83+
```
84+
85+
The precise layout of the files is up to you.
86+
The organization of the files will correspond to the HTML files generated, so keep in mind that the file layout is part of the URL of each chapter.
87+
88+
While the `mdbook serve` command is running, you can open any of the chapter files and start editing them.
89+
Each time you save the file, `mdbook` will rebuild the book and refresh your web browser.
90+
91+
Check out the [Markdown chapter](../format/markdown.md) for more information on formatting the content of your chapters.
92+
93+
All other files in the `src` directory will be included in the output.
94+
So if you have images or other static files, just include them somewhere in the `src` directory.
95+
96+
## Publishing a book
97+
98+
Once you've written your book, you may want to host it somewhere for others to view.
99+
The first step is to build the output of the book.
100+
This can be done with the `mbdook build` command in the same directory where the `book.toml` file is located:
101+
102+
```sh
103+
mdbook build
104+
```
105+
106+
This will generate a directory named `book` which contains the HTML content of your book.
107+
You can then place this directory on any web server to host it.
108+
109+
For more information about publishing and deploying, check out the [Continuous Integration chapter](../continuous-integration.md) for more.

‎guide/src/guide/installation.md

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Installation
2+
3+
There are multiple ways to install the mdBook CLI tool.
4+
Choose any one of the methods below that best suit your needs.
5+
If you are installing mdBook for automatic deployment, check out the [continuous integration] chapter for more examples on how to install.
6+
7+
[continuous integration]: ../continuous-integration.md
8+
9+
## Pre-compiled binaries
10+
11+
Executable binaries are available for download on the [GitHub Releases page][releases].
12+
Download the binary for your platform (Windows, macOS, or Linux) and extract the archive.
13+
The archive contains an `mdbook` executable which you can run to build your books.
14+
15+
To make it easier to run, put the path to the binary into your `PATH`.
16+
17+
[releases]: https://github.com/rust-lang/mdBook/releases
18+
19+
## Build from source using Rust
20+
21+
To build the `mdbook` executable from source, you will first need to install Rust and Cargo.
22+
Follow the instructions on the [Rust installation page].
23+
mdBook currently requires at least Rust version 1.46.
24+
25+
Once you have installed Rust, the following command can be used to build and install mdBook:
26+
27+
```sh
28+
cargo install mdbook
29+
```
30+
31+
This will automatically download mdBook from [crates.io], build it, and install it in Cargo's global binary directory (`~/.cargo/bin/` by default).
32+
33+
[Rust installation page]: https://www.rust-lang.org/tools/install
34+
[crates.io]: https://crates.io/
35+
36+
### Installing the latest master version
37+
38+
The version published to crates.io will ever so slightly be behind the version hosted on GitHub.
39+
If you need the latest version you can build the git version of mdBook yourself.
40+
Cargo makes this ***super easy***!
41+
42+
```sh
43+
cargo install --git https://github.com/rust-lang/mdBook.git mdbook
44+
```
45+
46+
Again, make sure to add the Cargo bin directory to your `PATH`.
47+
48+
If you are interested in making modifications to mdBook itself, check out the [Contributing Guide] for more information.
49+
50+
[Contributing Guide]: https://github.com/rust-lang/mdBook/blob/master/CONTRIBUTING.md

‎guide/src/guide/reading.md

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Reading Books
2+
3+
This chapter gives an introduction on how to interact with a book produced by mdBook.
4+
This assumes you are reading an HTML book.
5+
The options and formatting will be different for other output formats such as PDF.
6+
7+
A book is organized into *chapters*.
8+
Each chapter is a separate page.
9+
Chapters can be nested into a hierarchy of sub-chapters.
10+
Typically, each chapter will be organized into a series of *headings* to subdivide a chapter.
11+
12+
## Navigation
13+
14+
There are several methods for navigating through the chapters of a book.
15+
16+
The **sidebar** on the left provides a list of all chapters.
17+
Clicking on any of the chapter titles will load that page.
18+
19+
The sidebar may not automatically appear if the window is too narrow, particularly on mobile displays.
20+
In that situation, the menu icon (three horizontal bars) at the top-left of the page can be pressed to open and close the sidebar.
21+
22+
The **arrow buttons** at the bottom of the page can be used to navigate to the previous or the next chapter.
23+
24+
The **left and right arrow keys** on the keyboard can be used to navigate to the previous or the next chapter.
25+
26+
## Top menu bar
27+
28+
The menu bar at the top of the page provides some icons for interacting with the book.
29+
The icons displayed will depend on the settings of how the book was generated.
30+
31+
| Icon | Description |
32+
|------|-------------|
33+
| <i class="fa fa-bars"></i> | Opens and closes the chapter listing sidebar. |
34+
| <i class="fa fa-paint-brush"></i> | Opens a picker to choose a different color theme. |
35+
| <i class="fa fa-search"></i> | Opens a search bar for searching within the book. |
36+
| <i class="fa fa-print"></i> | Instructs the web browser to print the entire book. |
37+
| <i class="fa fa-github"></i> | Opens a link to the website that hosts the source code of the book. |
38+
| <i class="fa fa-edit"></i> | Opens a page to directly edit the source of the page you are currently reading. |
39+
40+
Tapping the menu bar will scroll the page to the top.
41+
42+
## Search
43+
44+
Each book has a built-in search system.
45+
Pressing the search icon (<i class="fa fa-search"></i>) in the menu bar, or pressing the `S` key on the keyboard will open an input box for entering search terms.
46+
Typing some terms will show matching chapters and sections in real time.
47+
48+
Clicking any of the results will jump to that section.
49+
The up and down arrow keys can be used to navigate the results, and enter will open the highlighted section.
50+
51+
After loading a search result, the matching search terms will be highlighted in the text.
52+
Clicking a highlighted word or pressing the `Esc` key will remove the highlighting.
53+
54+
## Code blocks
55+
56+
mdBook books are often used for programming projects, and thus support highlighting code blocks and samples.
57+
Code blocks may contain several different icons for interacting with them:
58+
59+
| Icon | Description |
60+
|------|-------------|
61+
| <i class="fa fa-copy"></i> | Copies the code block into your local clipboard, to allow pasting into another application. |
62+
| <i class="fa fa-play"></i> | For Rust code examples, this will execute the sample code and display the compiler output just below the example (see [playground]). |
63+
| <i class="fa fa-eye"></i> | For Rust code examples, this will toggle visibility of "hidden" lines. Sometimes, larger examples will hide lines which are not particularly relevant to what is being illustrated (see [hiding code lines]). |
64+
| <i class="fa fa-history"></i> | For [editable code examples][editor], this will undo any changes you have made. |
65+
66+
Here's an example:
67+
68+
```rust
69+
println!("Hello, World!");
70+
```
71+
72+
[editor]: ../format/theme/editor.md
73+
[playground]: ../format/mdbook.md#rust-playground
74+
[hiding code lines]: ../format/mdbook.md#hiding-code-lines

‎guide/src/misc/introduction.md

-3
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.