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

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

Fields

content: Vec<BookItem>

Methods

impl MDBook
[src]

fn new(root: &Path) -> MDBook

Create a new MDBook struct with root directory root

  • The default source directory is set to root/src
  • The default output directory is set to root/book

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

fn iter(&self) -> BookItems

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.

fn init(&mut self) -> Result<()Box<Error>>

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.

fn build(&mut self) -> Result<()Box<Error>>

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.

fn copy_theme(&self) -> Result<()Box<Error>>

fn read_config(self) -> Self

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

let mut book = MDBook::new(Path::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.

fn set_renderer(self, renderer: Box<Renderer>) -> Self

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 mut book = MDBook::new(Path::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()

fn test(&mut self) -> Result<()Box<Error>>

fn set_dest(self, dest: &Path) -> Self

fn get_dest(&self) -> &Path

fn set_src(self, src: &Path) -> Self

fn get_src(&self) -> &Path

fn set_title(self, title: &str) -> Self

fn get_title(&self) -> &str

fn set_author(self, author: &str) -> Self

fn get_author(&self) -> &str

fn set_description(self, description: &str) -> Self

fn get_description(&self) -> &str