Struct mdbook::book::MDBook [] [src]

pub struct MDBook {
    pub content: Vec<BookItem>,
    pub create_missing: bool,
    // some fields omitted
}

Fields

Should mdbook build create files referenced from SUMMARY.md if they don't exist

Methods

impl MDBook
[src]

Create a new MDBook struct with root directory root

Examples

let book = MDBook::new("root_dir");

In this example, root_dir will be the root directory of our book and is specified in function of the current working directory by using a relative path instead of an absolute path.

Default directory paths:

  • source: root/src
  • output: root/book
  • theme: root/theme

They can both be changed by using set_src() and set_dest()

Returns a flat depth-first iterator over the elements of the book, it returns an BookItem enum: (section: String, bookitem: &BookItem)

for item in book.iter() {
    match item {
        &BookItem::Chapter(ref section, ref chapter) => {},
        &BookItem::Affix(ref chapter) => {},
        &BookItem::Spacer => {},
    }
}

// would print something like this:
// 1. Chapter 1
// 1.1 Sub Chapter
// 1.2 Sub Chapter
// 2. Chapter 2
//
// etc.

init() 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 paths given as source and output directories and adds a SUMMARY.md and a chapter_1.md to the source directory.

The build() method is the one where everything happens. First it parses SUMMARY.md to construct the book's structure in the form of a Vec<BookItem> and then calls render() method of the current renderer.

It is the renderer who generates all the output files.

Parses the book.json file (if it exists) to extract the configuration parameters. The book.json file should be in the root directory of the book. The root directory is the one specified when creating a new MDBook

You can change the default renderer to another one by using this method. The only requirement is for your renderer to implement the Renderer trait

extern crate mdbook;
use mdbook::MDBook;
use mdbook::renderer::HtmlHandlebars;

fn main() {
    let book = MDBook::new("mybook")
                        .set_renderer(Box::new(HtmlHandlebars::new()));

// In this example we replace the default renderer
// by the default renderer...
// Don't forget to put your renderer in a Box
}

note: Don't forget to put your renderer in a Box before passing it to set_renderer()