Skip to content

Commit 836546c

Browse files
authored
Merge pull request #1544 from joshrotenberg/guide_configuration_restructure
Restructure guide configuration section
2 parents 89a2e39 + aa4cb94 commit 836546c

File tree

8 files changed

+217
-201
lines changed

8 files changed

+217
-201
lines changed

guide/book.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ boost-hierarchy = 2
2525
boost-paragraph = 1
2626
expand = true
2727
heading-split-level = 2
28+
29+
[output.html.redirect]
30+
"/format/config.html" = "configuration/index.html"

guide/src/SUMMARY.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
- [Format](format/README.md)
1212
- [SUMMARY.md](format/summary.md)
1313
- [Draft chapter]()
14-
- [Configuration](format/config.md)
14+
- [Configuration](format/configuration/README.md)
15+
- [General](format/configuration/general.md)
16+
- [Preprocessors](format/configuration/preprocessors.md)
17+
- [Renderers](format/configuration/renderers.md)
18+
- [Environment Variables](format/configuration/environment-variables.md)
1519
- [Theme](format/theme/README.md)
1620
- [index.hbs](format/theme/index-hbs.md)
1721
- [Syntax highlighting](format/theme/syntax-highlighting.md)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Configuration
2+
3+
This section details the configuration options available in the ***book.toml***:
4+
- **[General]** configuration including the `book`, `rust`, `build` sections
5+
- **[Preprocessor]** configuration for default and custom book preprocessors
6+
- **[Renderer]** configuration for the HTML, Markdown and custom renderers
7+
- **[Environment Variable]** configuration for overriding configuration options in your environment
8+
9+
[General]: general.md
10+
[Preprocessor]: preprocessors.md
11+
[Renderer]: renderers.md
12+
[Environment Variable]: environment-variables.md
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Environment Variables
2+
3+
All configuration values can be overridden from the command line by setting the
4+
corresponding environment variable. Because many operating systems restrict
5+
environment variables to be alphanumeric characters or `_`, the configuration
6+
key needs to be formatted slightly differently to the normal `foo.bar.baz` form.
7+
8+
Variables starting with `MDBOOK_` are used for configuration. The key is created
9+
by removing the `MDBOOK_` prefix and turning the resulting string into
10+
`kebab-case`. Double underscores (`__`) separate nested keys, while a single
11+
underscore (`_`) is replaced with a dash (`-`).
12+
13+
For example:
14+
15+
- `MDBOOK_foo` -> `foo`
16+
- `MDBOOK_FOO` -> `foo`
17+
- `MDBOOK_FOO__BAR` -> `foo.bar`
18+
- `MDBOOK_FOO_BAR` -> `foo-bar`
19+
- `MDBOOK_FOO_bar__baz` -> `foo-bar.baz`
20+
21+
So by setting the `MDBOOK_BOOK__TITLE` environment variable you can override the
22+
book's title without needing to touch your `book.toml`.
23+
24+
> **Note:** To facilitate setting more complex config items, the value of an
25+
> environment variable is first parsed as JSON, falling back to a string if the
26+
> parse fails.
27+
>
28+
> This means, if you so desired, you could override all book metadata when
29+
> building the book with something like
30+
>
31+
> ```shell
32+
> $ export MDBOOK_BOOK="{'title': 'My Awesome Book', authors: ['Michael-F-Bryan']}"
33+
> $ mdbook build
34+
> ```
35+
36+
The latter case may be useful in situations where `mdbook` is invoked from a
37+
script or CI, where it sometimes isn't possible to update the `book.toml` before
38+
building.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# General Configuration
2+
3+
You can configure the parameters for your book in the ***book.toml*** file.
4+
5+
Here is an example of what a ***book.toml*** file might look like:
6+
7+
```toml
8+
[book]
9+
title = "Example book"
10+
author = "John Doe"
11+
description = "The example book covers examples."
12+
13+
[rust]
14+
edition = "2018"
15+
16+
[build]
17+
build-dir = "my-example-book"
18+
create-missing = false
19+
20+
[preprocessor.index]
21+
22+
[preprocessor.links]
23+
24+
[output.html]
25+
additional-css = ["custom.css"]
26+
27+
[output.html.search]
28+
limit-results = 15
29+
```
30+
31+
## Supported configuration options
32+
33+
It is important to note that **any** relative path specified in the
34+
configuration will always be taken relative from the root of the book where the
35+
configuration file is located.
36+
37+
### General metadata
38+
39+
This is general information about your book.
40+
41+
- **title:** The title of the book
42+
- **authors:** The author(s) of the book
43+
- **description:** A description for the book, which is added as meta
44+
information in the html `<head>` of each page
45+
- **src:** By default, the source directory is found in the directory named
46+
`src` directly under the root folder. But this is configurable with the `src`
47+
key in the configuration file.
48+
- **language:** The main language of the book, which is used as a language attribute `<html lang="en">` for example.
49+
50+
**book.toml**
51+
```toml
52+
[book]
53+
title = "Example book"
54+
authors = ["John Doe", "Jane Doe"]
55+
description = "The example book covers examples."
56+
src = "my-src" # the source files will be found in `root/my-src` instead of `root/src`
57+
language = "en"
58+
```
59+
60+
### Rust options
61+
62+
Options for the Rust language, relevant to running tests and playground
63+
integration.
64+
65+
- **edition**: Rust edition to use by default for the code snippets. Default
66+
is "2015". Individual code blocks can be controlled with the `edition2015`
67+
or `edition2018` annotations, such as:
68+
69+
~~~text
70+
```rust,edition2015
71+
// This only works in 2015.
72+
let try = true;
73+
```
74+
~~~
75+
76+
### Build options
77+
78+
This controls the build process of your book.
79+
80+
- **build-dir:** The directory to put the rendered book in. By default this is
81+
`book/` in the book's root directory.
82+
- **create-missing:** By default, any missing files specified in `SUMMARY.md`
83+
will be created when the book is built (i.e. `create-missing = true`). If this
84+
is `false` then the build process will instead exit with an error if any files
85+
do not exist.
86+
- **use-default-preprocessors:** Disable the default preprocessors of (`links` &
87+
`index`) by setting this option to `false`.
88+
89+
If you have the same, and/or other preprocessors declared via their table
90+
of configuration, they will run instead.
91+
92+
- For clarity, with no preprocessor configuration, the default `links` and
93+
`index` will run.
94+
- Setting `use-default-preprocessors = false` will disable these
95+
default preprocessors from running.
96+
- Adding `[preprocessor.links]`, for example, will ensure, regardless of
97+
`use-default-preprocessors` that `links` it will run.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Configuring Preprocessors
2+
3+
The following preprocessors are available and included by default:
4+
5+
- `links`: Expand the `{{ #playground }}`, `{{ #include }}`, and `{{ #rustdoc_include }}` handlebars
6+
helpers in a chapter to include the contents of a file.
7+
- `index`: Convert all chapter files named `README.md` into `index.md`. That is
8+
to say, all `README.md` would be rendered to an index file `index.html` in the
9+
rendered book.
10+
11+
12+
**book.toml**
13+
```toml
14+
[build]
15+
build-dir = "build"
16+
create-missing = false
17+
18+
[preprocessor.links]
19+
20+
[preprocessor.index]
21+
```
22+
23+
### Custom Preprocessor Configuration
24+
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+
29+
For example
30+
31+
```toml
32+
[preprocessor.links]
33+
# set the renderers this preprocessor will run for
34+
renderers = ["html"]
35+
some_extra_feature = true
36+
```
37+
38+
#### Locking a Preprocessor dependency to a renderer
39+
40+
You can explicitly specify that a preprocessor should run for a renderer by
41+
binding the two together.
42+
43+
```toml
44+
[preprocessor.mathjax]
45+
renderers = ["html"] # mathjax only makes sense with the HTML renderer
46+
```
47+
48+
### Provide Your Own Command
49+
50+
By default when you add a `[preprocessor.foo]` table to your `book.toml` file,
51+
`mdbook` will try to invoke the `mdbook-foo` executable. If you want to use a
52+
different program name or pass in command-line arguments, this behaviour can
53+
be overridden by adding a `command` field.
54+
55+
```toml
56+
[preprocessor.random]
57+
command = "python random.py"
58+
```

0 commit comments

Comments
 (0)