Skip to content

Commit fad53f7

Browse files
committed
Update guide to accommodate crate split
This updates the docs now that the crate has been split into multiple crates.
1 parent dcfb527 commit fad53f7

File tree

3 files changed

+31
-41
lines changed

3 files changed

+31
-41
lines changed

guide/src/for_developers/README.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# For Developers
22

33
While `mdbook` is mainly used as a command line tool, you can also import the
4-
underlying library directly and use that to manage a book. It also has a fairly
4+
underlying libraries directly and use those to manage a book. It also has a fairly
55
flexible plugin mechanism, allowing you to create your own custom tooling and
66
consumers (often referred to as *backends*) if you need to do some analysis of
77
the book or render it in a different format.
@@ -14,7 +14,6 @@ The two main ways a developer can hook into the book's build process is via,
1414
- [Preprocessors](preprocessors.md)
1515
- [Alternative Backends](backends.md)
1616

17-
1817
## The Build Process
1918

2019
The process of rendering a book project goes through several steps.
@@ -28,20 +27,18 @@ The process of rendering a book project goes through several steps.
2827
1. Run all the preprocessors.
2928
2. Call the backend to render the processed result.
3029

31-
3230
## Using `mdbook` as a Library
3331

34-
The `mdbook` binary is just a wrapper around the `mdbook` crate, exposing its
35-
functionality as a command-line program. As such it is quite easy to create your
36-
own programs which use `mdbook` internally, adding your own functionality (e.g.
37-
a custom preprocessor) or tweaking the build process.
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.
3836

39-
The easiest way to find out how to use the `mdbook` crate is by looking at the
37+
The easiest way to find out how to use the `mdbook-driver` crate is by looking at the
4038
[API Docs]. The top level documentation explains how one would use the
4139
[`MDBook`] type to load and build a book, while the [config] module gives a good
4240
explanation on the configuration system.
4341

44-
45-
[`MDBook`]: https://docs.rs/mdbook/*/mdbook/book/struct.MDBook.html
46-
[API Docs]: https://docs.rs/mdbook/*/mdbook/
47-
[config]: https://docs.rs/mdbook/*/mdbook/config/index.html
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

guide/src/for_developers/backends.md

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ This page will step you through creating your own alternative backend in the for
1616
of a simple word counting program. Although it will be written in Rust, there's
1717
no reason why it couldn't be accomplished using something like Python or Ruby.
1818

19-
First you'll want to create a new binary program and add `mdbook` as a
19+
First you'll want to create a new binary program and add `mdbook-renderer` as a
2020
dependency.
2121

2222
```shell
2323
$ cargo new --bin mdbook-wordcount
2424
$ cd mdbook-wordcount
25-
$ cargo add mdbook
25+
$ cargo add mdbook-renderer
2626
```
2727

2828
When our `mdbook-wordcount` plugin is invoked, `mdbook` will send it a JSON
@@ -33,10 +33,8 @@ This is all the boilerplate necessary for our backend to load the book.
3333

3434
```rust
3535
// src/main.rs
36-
extern crate mdbook;
37-
3836
use std::io;
39-
use mdbook::renderer::RenderContext;
37+
use mdbook_renderer::RenderContext;
4038

4139
fn main() {
4240
let mut stdin = io::stdin();
@@ -45,13 +43,12 @@ fn main() {
4543
```
4644

4745
> **Note:** The `RenderContext` contains a `version` field. This lets backends
48-
figure out whether they are compatible with the version of `mdbook` it's being
49-
called by. This `version` comes directly from the corresponding field in
50-
`mdbook`'s `Cargo.toml`.
51-
52-
It is recommended that backends use the [`semver`] crate to inspect this field
53-
and emit a warning if there may be a compatibility issue.
54-
46+
> figure out whether they are compatible with the version of `mdbook` it's being
47+
> called by. This `version` comes directly from the corresponding field in
48+
> `mdbook`'s `Cargo.toml`.
49+
>
50+
> It is recommended that backends use the [`semver`] crate to inspect this field
51+
> and emit a warning if there may be a compatibility issue.
5552
5653
## Inspecting the Book
5754

@@ -183,9 +180,7 @@ $ cargo add serde serde_derive
183180
And then you can create the config struct,
184181

185182
```rust
186-
extern crate serde;
187-
#[macro_use]
188-
extern crate serde_derive;
183+
use serde_derive::{Serialize, Deserialize};
189184

190185
...
191186

@@ -337,10 +332,10 @@ the source code or ask questions.
337332

338333

339334
[Third Party Plugins]: https://github.com/rust-lang/mdBook/wiki/Third-party-plugins
340-
[`RenderContext`]: https://docs.rs/mdbook/*/mdbook/renderer/struct.RenderContext.html
341-
[`RenderContext::from_json()`]: https://docs.rs/mdbook/*/mdbook/renderer/struct.RenderContext.html#method.from_json
335+
[`RenderContext`]: https://docs.rs/mdbook-renderer/latest/mdbook_renderer/struct.RenderContext.html
336+
[`RenderContext::from_json()`]: https://docs.rs/mdbook-renderer/latest/mdbook_renderer/struct.RenderContext.html#method.from_json
342337
[`semver`]: https://crates.io/crates/semver
343-
[`Book`]: https://docs.rs/mdbook/*/mdbook/book/struct.Book.html
344-
[`Book::iter()`]: https://docs.rs/mdbook/*/mdbook/book/struct.Book.html#method.iter
345-
[`Config`]: https://docs.rs/mdbook/*/mdbook/config/struct.Config.html
338+
[`Book`]: https://docs.rs/mdbook-renderer/latest/mdbook_renderer/book/struct.Book.html
339+
[`Book::iter()`]: https://docs.rs/mdbook-renderer/latest/mdbook_renderer/book/struct.Book.html#method.iter
340+
[`Config`]: https://docs.rs/mdbook-renderer/latest/mdbook_renderer/config/struct.Config.html
346341
[issue tracker]: https://github.com/rust-lang/mdBook/issues

guide/src/for_developers/preprocessors.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ be adapted for other preprocessors.
4545

4646
## Hints For Implementing A Preprocessor
4747

48-
By pulling in `mdbook` as a library, preprocessors can have access to the
48+
By pulling in `mdbook-preprocessor` as a library, preprocessors can have access to the
4949
existing infrastructure for dealing with books.
5050

5151
For example, a custom preprocessor could use the
@@ -60,9 +60,7 @@ chapters) or via the `Book::for_each_mut()` convenience method.
6060
The `chapter.content` is just a string which happens to be markdown. While it's
6161
entirely possible to use regular expressions or do a manual find & replace,
6262
you'll probably want to process the input into something more computer-friendly.
63-
The [`pulldown-cmark`][pc] crate implements a production-quality event-based
64-
Markdown parser, with the [`pulldown-cmark-to-cmark`][pctc] crate allowing you to
65-
translate events back into markdown text.
63+
The [`mdbook-markdown`] crate exposes the [`pulldown-cmark`][pc] crate used by mdBook to parse Markdown. The [`pulldown-cmark-to-cmark`][pctc] crate can be used to translate events back into markdown text.
6664

6765
The following code block shows how to remove all emphasis from markdown,
6866
without accidentally breaking the document.
@@ -100,11 +98,11 @@ if __name__ == '__main__':
10098

10199

102100
[emphasis-example]: https://github.com/rust-lang/mdBook/tree/master/examples/remove-emphasis/
103-
[preprocessor-docs]: https://docs.rs/mdbook/latest/mdbook/preprocess/trait.Preprocessor.html
104101
[pc]: https://crates.io/crates/pulldown-cmark
105102
[pctc]: https://crates.io/crates/pulldown-cmark-to-cmark
106103
[an example no-op preprocessor]: https://github.com/rust-lang/mdBook/blob/master/examples/nop-preprocessor.rs
107-
[`CmdPreprocessor::parse_input()`]: https://docs.rs/mdbook/latest/mdbook/preprocess/trait.Preprocessor.html#method.parse_input
108-
[`Book::for_each_mut()`]: https://docs.rs/mdbook/latest/mdbook/book/struct.Book.html#method.for_each_mut
109-
[`PreprocessorContext`]: https://docs.rs/mdbook/latest/mdbook/preprocess/struct.PreprocessorContext.html
110-
[`Book`]: https://docs.rs/mdbook/latest/mdbook/book/struct.Book.html
104+
[`CmdPreprocessor::parse_input()`]: https://docs.rs/mdbook-preprocessor/latest/mdbook_preprocessor/trait.Preprocessor.html#method.parse_input
105+
[`Book::for_each_mut()`]: https://docs.rs/mdbook-preprocessor/latest/mdbook_preprocessor/book/struct.Book.html#method.for_each_mut
106+
[`PreprocessorContext`]: https://docs.rs/mdbook-preprocessor/latest/mdbook_preprocessor/struct.PreprocessorContext.html
107+
[`Book`]: https://docs.rs/mdbook-preprocessor/latest/mdbook_preprocessor/book/struct.Book.html
108+
[`mdbook-markdown`]: https://docs.rs/mdbook-markdown/latest/mdbook_markdown/

0 commit comments

Comments
 (0)