Change name of link preprocessor

This commit is contained in:
Jaime Valdemoros 2018-01-07 19:25:47 +00:00
parent 4cc708e00f
commit 144358bec6
2 changed files with 14 additions and 11 deletions

View File

@ -224,7 +224,7 @@ impl MDBook {
let temp_dir = TempDir::new("mdbook")?; let temp_dir = TempDir::new("mdbook")?;
let replace_all_preprocessor = preprocess::links::ReplaceAllPreprocessor { let replace_all_preprocessor = preprocess::links::LinkPreprocessor {
src_dir: self.source_dir(), src_dir: self.source_dir(),
}; };
@ -337,24 +337,27 @@ fn determine_renderers(config: &Config) -> Vec<Box<Renderer>> {
fn determine_preprocessors(md_book: &MDBook) -> Vec<Box<Preprocessor>> { fn determine_preprocessors(md_book: &MDBook) -> Vec<Box<Preprocessor>> {
let mut preprocessors: Vec<Box<Preprocessor>> = Vec::new(); let mut preprocessors: Vec<Box<Preprocessor>> = Vec::new();
if let Some(preprocess_array) = md_book.config.get("pre_process").and_then(|o| o.as_array()) { if let Some(preprocess_array) = md_book.config.get("preprocess").and_then(|o| o.as_array()) {
for key in preprocess_array.iter() { for key in preprocess_array.iter() {
if key.as_str().map_or(false, |key| key == "links") { match key.as_str() {
let replace_all_preprocessor = preprocess::links::ReplaceAllPreprocessor { Some(key) if key == "links" => {
let link_preprocessor = preprocess::links::LinkPreprocessor {
src_dir: md_book.source_dir(), src_dir: md_book.source_dir(),
}; };
preprocessors.push(Box::new(replace_all_preprocessor)) preprocessors.push(Box::new(link_preprocessor ))
}
_ => {}
} }
} }
} }
if preprocessors.is_empty() { if preprocessors.is_empty() {
let replace_all_preprocessor = preprocess::links::ReplaceAllPreprocessor { let link_preprocessor = preprocess::links::LinkPreprocessor {
src_dir: md_book.source_dir(), src_dir: md_book.source_dir(),
}; };
preprocessors.push(Box::new(replace_all_preprocessor)) preprocessors.push(Box::new(link_preprocessor))
} }
preprocessors preprocessors

View File

@ -10,11 +10,11 @@ use book::{Book, BookItem};
const ESCAPE_CHAR: char = '\\'; const ESCAPE_CHAR: char = '\\';
pub struct ReplaceAllPreprocessor { pub struct LinkPreprocessor {
pub src_dir: PathBuf pub src_dir: PathBuf
} }
impl Preprocessor for ReplaceAllPreprocessor { impl Preprocessor for LinkPreprocessor {
fn run(&self, book: &mut Book) -> Result<()> { fn run(&self, book: &mut Book) -> Result<()> {
for section in &mut book.sections { for section in &mut book.sections {
match *section { match *section {