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