diff --git a/src/book/book.rs b/src/book/book.rs index b69e98ab..a14d31b9 100644 --- a/src/book/book.rs +++ b/src/book/book.rs @@ -179,7 +179,7 @@ impl Chapter { /// /// You need to pass in the book's source directory because all the links in /// `SUMMARY.md` give the chapter locations relative to it. -fn load_book_from_disk>(summary: &Summary, src_dir: P) -> Result { +pub(crate) fn load_book_from_disk>(summary: &Summary, src_dir: P) -> Result { debug!("Loading the book from disk"); let src_dir = src_dir.as_ref(); diff --git a/src/book/mod.rs b/src/book/mod.rs index a597023b..5bd2b194 100644 --- a/src/book/mod.rs +++ b/src/book/mod.rs @@ -95,6 +95,29 @@ impl MDBook { }) } + /// Load a book from its root directory using a custom config and a custom summary. + pub fn load_with_config_and_summary>( + book_root: P, + config: Config, + summary: Summary + ) -> Result { + let root = book_root.into(); + + let src_dir = root.join(&config.book.src); + let book = book::load_book_from_disk(&summary, &src_dir)?; + + let renderers = determine_renderers(&config); + let preprocessors = determine_preprocessors(&config)?; + + Ok(MDBook { + root, + config, + book, + renderers, + preprocessors, + }) + } + /// Returns a flat depth-first iterator over the elements of the book, /// it returns an [BookItem enum](bookitem.html): /// `(section: String, bookitem: &BookItem)`