| 1 |
# For developers |
| 2 |
|
| 3 |
While `mdbook` is mainly used as a command line tool, you can also import the |
| 4 |
underlying libraries directly and use those to manage a book. It also has a fairly |
| 5 |
flexible plugin mechanism, allowing you to create your own custom tooling and |
| 6 |
consumers (often referred to as *backends*) if you need to do some analysis of |
| 7 |
the book or render it in a different format. |
| 8 |
|
| 9 |
The *For Developers* chapters are here to show you the more advanced usage of |
| 10 |
`mdbook`. |
| 11 |
|
| 12 |
The two main ways a developer can hook into the book's build process is via, |
| 13 |
|
| 14 |
- [Preprocessors](preprocessors.md) |
| 15 |
- [Alternative Backends](backends.md) |
| 16 |
|
| 17 |
## The build process |
| 18 |
|
| 19 |
The process of rendering a book project goes through several steps. |
| 20 |
|
| 21 |
1. Load the book |
| 22 |
- Parse the `book.toml`, falling back to the default `Config` if it doesn't |
| 23 |
exist |
| 24 |
- Load the book chapters into memory |
| 25 |
- Discover which preprocessors/backends should be used |
| 26 |
2. For each backend: |
| 27 |
1. Run all the preprocessors. |
| 28 |
2. Call the backend to render the processed result. |
| 29 |
|
| 30 |
## Using `mdbook` as a library |
| 31 |
|
| 32 |
The `mdbook` binary is just a wrapper around the underlying mdBook crates, |
| 33 |
exposing their functionality as a command-line program. If you want to |
| 34 |
programmatically drive mdBook, you can use the [`mdbook-driver`] crate. |
| 35 |
This can be used to add your own functionality or tweak the build process. |
| 36 |
|
| 37 |
The easiest way to find out how to use the `mdbook-driver` crate is by looking at the |
| 38 |
[API Docs]. The top level documentation explains how one would use the |
| 39 |
[`MDBook`] type to load and build a book, while the [config] module gives a good |
| 40 |
explanation on the configuration system. |
| 41 |
|
| 42 |
[`MDBook`]: https://docs.rs/mdbook-driver/latest/mdbook_driver/struct.MDBook.html |
| 43 |
[API Docs]: https://docs.rs/mdbook-driver/latest/mdbook_driver/ |
| 44 |
[config]: https://docs.rs/mdbook-driver/latest/mdbook_driver/config/index.html |