pub struct MDBook {
pub root: PathBuf,
pub config: Config,
pub book: Book,
/* private fields */
}
Expand description
The object used to manage and build a book.
Fields§
§root: PathBuf
The book’s root directory.
config: Config
The configuration used to tweak now a book is built.
book: Book
A representation of the book’s contents in memory.
Implementations§
Source§impl MDBook
impl MDBook
Sourcepub fn load<P: Into<PathBuf>>(book_root: P) -> Result<MDBook>
pub fn load<P: Into<PathBuf>>(book_root: P) -> Result<MDBook>
Load a book from its root directory on disk.
Sourcepub fn load_with_config<P: Into<PathBuf>>(
book_root: P,
config: Config,
) -> Result<MDBook>
pub fn load_with_config<P: Into<PathBuf>>( book_root: P, config: Config, ) -> Result<MDBook>
Load a book from its root directory using a custom Config
.
Sourcepub fn load_with_config_and_summary<P: Into<PathBuf>>(
book_root: P,
config: Config,
summary: Summary,
) -> Result<MDBook>
pub fn load_with_config_and_summary<P: Into<PathBuf>>( book_root: P, config: Config, summary: Summary, ) -> Result<MDBook>
Load a book from its root directory using a custom Config
and a custom summary.
Sourcepub fn iter(&self) -> BookItems<'_> ⓘ
pub fn iter(&self) -> BookItems<'_> ⓘ
Returns a flat depth-first iterator over the elements of the book,
it returns a BookItem
enum:
(section: String, bookitem: &BookItem)
for item in book.iter() {
match *item {
BookItem::Chapter(ref chapter) => {},
BookItem::Separator => {},
BookItem::PartTitle(ref title) => {}
}
}
// would print something like this:
// 1. Chapter 1
// 1.1 Sub Chapter
// 1.2 Sub Chapter
// 2. Chapter 2
//
// etc.
Sourcepub fn init<P: Into<PathBuf>>(book_root: P) -> BookBuilder
pub fn init<P: Into<PathBuf>>(book_root: P) -> BookBuilder
init()
gives you a BookBuilder
which you can use to setup a new book
and its accompanying directory structure.
The BookBuilder
creates some boilerplate files and directories to get
you started with your book.
book-test/
├── book
└── src
├── chapter_1.md
└── SUMMARY.md
It uses the path provided as the root directory for your book, then adds
in a src/
directory containing a SUMMARY.md
and chapter_1.md
file
to get you started.
Sourcepub fn build(&self) -> Result<()>
pub fn build(&self) -> Result<()>
Tells the renderer to build our book and put it in the build directory.
Sourcepub fn preprocess_book(
&self,
renderer: &dyn Renderer,
) -> Result<(Book, PreprocessorContext)>
pub fn preprocess_book( &self, renderer: &dyn Renderer, ) -> Result<(Book, PreprocessorContext)>
Run preprocessors and return the final book.
Sourcepub fn execute_build_process(&self, renderer: &dyn Renderer) -> Result<()>
pub fn execute_build_process(&self, renderer: &dyn Renderer) -> Result<()>
Run the entire build process for a particular Renderer
.
Sourcepub fn with_renderer<R: Renderer + 'static>(&mut self, renderer: R) -> &mut Self
pub fn with_renderer<R: Renderer + 'static>(&mut self, renderer: R) -> &mut Self
You can change the default renderer to another one by using this method.
The only requirement is that your renderer implement the Renderer
trait.
Sourcepub fn with_preprocessor<P: Preprocessor + 'static>(
&mut self,
preprocessor: P,
) -> &mut Self
pub fn with_preprocessor<P: Preprocessor + 'static>( &mut self, preprocessor: P, ) -> &mut Self
Register a Preprocessor
to be used when rendering the book.
Sourcepub fn test(&mut self, library_paths: Vec<&str>) -> Result<()>
pub fn test(&mut self, library_paths: Vec<&str>) -> Result<()>
Run rustdoc
tests on the book, linking against the provided libraries.
Sourcepub fn test_chapter(
&mut self,
library_paths: Vec<&str>,
chapter: Option<&str>,
) -> Result<()>
pub fn test_chapter( &mut self, library_paths: Vec<&str>, chapter: Option<&str>, ) -> Result<()>
Run rustdoc
tests on a specific chapter of the book, linking against the provided libraries.
If chapter
is None
, all tests will be run.
Sourcepub fn build_dir_for(&self, backend_name: &str) -> PathBuf
pub fn build_dir_for(&self, backend_name: &str) -> PathBuf
The logic for determining where a backend should put its build artefacts.
If there is only 1 renderer, put it in the directory pointed to by the
build.build_dir
key in Config
. If there is more than one then the
renderer gets its own directory within the main build dir.
i.e. If there were only one renderer (in this case, the HTML renderer):
- build/
- index.html
- …
Otherwise if there are multiple:
- build/
- epub/
- my_awesome_book.epub
- html/
- index.html
- …
- latex/
- my_awesome_book.tex
- epub/
Sourcepub fn source_dir(&self) -> PathBuf
pub fn source_dir(&self) -> PathBuf
Get the directory containing this book’s source files.