Skip to content

Commit dcfb527

Browse files
committed
Update crate docs
This updates the crate-level docs to add a little more detail for each crate. This also drops the `mdbook` library crate, as it is no longer needed.
1 parent e0a4fb1 commit dcfb527

File tree

8 files changed

+94
-81
lines changed

8 files changed

+94
-81
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/mdbook-driver/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ anyhow.workspace = true
1212
log.workspace = true
1313
mdbook-core.workspace = true
1414
mdbook-html.workspace = true
15+
mdbook-markdown.workspace = true
1516
mdbook-preprocessor.workspace = true
1617
mdbook-renderer.workspace = true
1718
mdbook-summary.workspace = true

crates/mdbook-driver/src/lib.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,62 @@
11
//! High-level library for running mdBook.
2+
//!
3+
//! This is the high-level library for running
4+
//! [mdBook](https://rust-lang.github.io/mdBook/). There are several
5+
//! reasons for using the programmatic API (over the CLI):
6+
//!
7+
//! - Integrate mdBook in a current project.
8+
//! - Extend the capabilities of mdBook.
9+
//! - Do some processing or test before building your book.
10+
//! - Accessing the public API to help create a new Renderer.
11+
//!
12+
//! ## Additional crates
13+
//!
14+
//! In addition to `mdbook-driver`, there are several other crates available
15+
//! for using and extending mdBook:
16+
//!
17+
//! - [`mdbook_preprocessor`]: Provides support for implementing preprocessors.
18+
//! - [`mdbook_renderer`]: Provides support for implementing renderers.
19+
//! - [`mdbook_markdown`]: The Markdown renderer.
20+
//! - [`mdbook_summary`]: The `SUMMARY.md` parser.
21+
//! - [`mdbook_html`]: The HTML renderer.
22+
//! - [`mdbook_core`]: An internal library that is used by the other crates
23+
//! for shared types. Types from this crate are rexported from the other
24+
//! crates as appropriate.
25+
//!
26+
//! ## Examples
27+
//!
28+
//! If creating a new book from scratch, you'll want to get a [`init::BookBuilder`] via
29+
//! the [`MDBook::init()`] method.
30+
//!
31+
//! ```rust,no_run
32+
//! use mdbook_driver::MDBook;
33+
//! use mdbook_driver::config::Config;
34+
//!
35+
//! let root_dir = "/path/to/book/root";
36+
//!
37+
//! // create a default config and change a couple things
38+
//! let mut cfg = Config::default();
39+
//! cfg.book.title = Some("My Book".to_string());
40+
//! cfg.book.authors.push("Michael-F-Bryan".to_string());
41+
//!
42+
//! MDBook::init(root_dir)
43+
//! .create_gitignore(true)
44+
//! .with_config(cfg)
45+
//! .build()
46+
//! .expect("Book generation failed");
47+
//! ```
48+
//!
49+
//! You can also load an existing book and build it.
50+
//!
51+
//! ```rust,no_run
52+
//! use mdbook_driver::MDBook;
53+
//!
54+
//! let root_dir = "/path/to/book/root";
55+
//!
56+
//! let mut md = MDBook::load(root_dir)
57+
//! .expect("Unable to load the book");
58+
//! md.build().expect("Building failed");
59+
//! ```
260
361
pub mod builtin_preprocessors;
462
pub mod builtin_renderers;

crates/mdbook-markdown/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
//! Markdown processing used in mdBook.
2+
//!
3+
//! This crate provides functions for processing Markdown in the same way as
4+
//! [mdBook](https://rust-lang.github.io/mdBook/). The [`pulldown_cmark`]
5+
//! crate is used as the underlying parser. This crate re-exports
6+
//! [`pulldown_cmark`] so that you can access its types.
7+
//!
8+
//! The parser in this library adds several modifications to the
9+
//! [`pulldown_cmark`] event stream. For example, it adjusts some links,
10+
//! modifies the behavior of footnotes, and adds various HTML wrappers.
211
312
use pulldown_cmark::{CodeBlockKind, CowStr, Event, Options, Parser, Tag, TagEnd, html};
413
use regex::Regex;
@@ -8,6 +17,7 @@ use std::fmt::Write;
817
use std::path::Path;
918
use std::sync::LazyLock;
1019

20+
#[doc(inline)]
1121
pub use pulldown_cmark;
1222

1323
#[cfg(test)]

crates/mdbook-preprocessor/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
//! Library to assist implementing an mdbook preprocessor.
2+
//!
3+
//! This library is used to implement a
4+
//! [preprocessor](https://rust-lang.github.io/mdBook/for_developers/preprocessors.html)
5+
//! for [mdBook](https://rust-lang.github.io/mdBook/). See the linked chapter
6+
//! for more information on how to implement a preprocessor.
27
38
use anyhow::Context;
49
use mdbook_core::book::Book;
@@ -17,6 +22,11 @@ pub use mdbook_core::errors;
1722

1823
/// An operation which is run immediately after loading a book into memory and
1924
/// before it gets rendered.
25+
///
26+
/// Types that implement the `Preprocessor` trait can be used with
27+
/// [`MDBook::with_preprocessor`] to programmatically add preprocessors.
28+
///
29+
/// [`MDBook::with_preprocessor`]: https://docs.rs/mdbook-driver/latest/mdbook_driver/struct.MDBook.html#method.with_preprocessor
2030
pub trait Preprocessor {
2131
/// Get the `Preprocessor`'s name.
2232
fn name(&self) -> &str;

crates/mdbook-renderer/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
//! Library to assist implementing an mdbook renderer.
2+
//!
3+
//! This library is used to implement a
4+
//! [renderer](https://rust-lang.github.io/mdBook/for_developers/backends.html)
5+
//! for [mdBook](https://rust-lang.github.io/mdBook/). See the linked chapter
6+
//! for more information on how to implement a renderer.
27
38
use anyhow::Context;
49
use mdbook_core::book::Book;
@@ -15,6 +20,11 @@ pub use mdbook_core::config;
1520
pub use mdbook_core::errors;
1621

1722
/// An mdbook backend.
23+
///
24+
/// Types that implement the `Renderer` trait can be used with
25+
/// [`MDBook::with_renderer`] to programmatically add renderers.
26+
///
27+
/// [`MDBook::with_renderer`]: https://docs.rs/mdbook-driver/latest/mdbook_driver/struct.MDBook.html#method.with_renderer
1828
pub trait Renderer {
1929
/// The `Renderer`'s name.
2030
fn name(&self) -> &str;

crates/mdbook-summary/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
//! Summary parser for mdBook.
2+
//!
3+
//! This is used to parse the
4+
//! [`SUMMARY.md`](https://rust-lang.github.io/mdBook/format/summary.html)
5+
//! file structure for [mdBook](https://rust-lang.github.io/mdBook/).
26
37
use anyhow::{Context, Error, Result, bail};
48
use log::{debug, trace, warn};

src/lib.rs

Lines changed: 0 additions & 81 deletions
This file was deleted.

0 commit comments

Comments
 (0)