Struct mdbook::book::MDBook
[−]
[src]
pub struct MDBook { pub content: Vec<BookItem>, pub create_missing: bool, // some fields omitted }
Fields
content: Vec<BookItem>
create_missing: bool
Should mdbook build
create files referenced from SUMMARY.md if they
don't exist
Methods
impl MDBook
[src]
fn new<P: Into<PathBuf>>(root: P) -> MDBook
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()
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<()>
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 create_gitignore(&self)
fn build(&mut self) -> Result<()>
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 get_gitignore(&self) -> PathBuf
fn copy_theme(&self) -> Result<()>
fn write_file<P: AsRef<Path>>(&self, filename: P, content: &[u8]) -> Result<()>
fn read_config(self) -> Result<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
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 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()