From 966811061b1be2679492d31da23e61b30cdf5e1a Mon Sep 17 00:00:00 2001 From: Jaime Valdemoros Date: Sun, 7 Jan 2018 16:40:17 +0000 Subject: [PATCH] Start determining preprocessors --- src/book/mod.rs | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/book/mod.rs b/src/book/mod.rs index 10a59dfc..4c801d6e 100644 --- a/src/book/mod.rs +++ b/src/book/mod.rs @@ -89,16 +89,19 @@ impl MDBook { let renderers = determine_renderers(&config); - let preprocessors = determine_preprocessors(&config); - - Ok(MDBook { + let mut md_book = MDBook { root, config, book, renderers, livereload, - preprocessors, - }) + preprocessors: vec![], + }; + + let preprocessors = determine_preprocessors(&md_book); + md_book.preprocessors = preprocessors; + + Ok(md_book) } /// Returns a flat depth-first iterator over the elements of the book, @@ -324,10 +327,22 @@ fn determine_renderers(config: &Config) -> Vec> { renderers } -/// Look at the `Config` and try to figure out what preprocessors to run. -fn determine_preprocessors(config: &Config) -> Vec> { +/// Look at the `MDBook` and try to figure out what preprocessors to run. +fn determine_preprocessors(md_book: &MDBook) -> Vec> { let mut preprocessors: Vec> = Vec::new(); + if let Some(preprocess_array) = md_book.config.get("pre_process").and_then(|o| o.as_array()) { + for key in preprocess_array.iter() { + if key.as_str().map_or(false, |key| key == "links") { + let preprocessor = preprocess::links::ReplaceAllPreprocessor { + src_dir: md_book.source_dir(), + }; + + preprocessors.push(Box::new(preprocessor)) + } + } + } + preprocessors }