A preprocessor is told which render it's running for

This commit is contained in:
Michael Bryan 2018-08-30 21:37:29 +08:00
parent 769fd94868
commit a0702037bd
No known key found for this signature in database
GPG Key ID: E9C602B0D9A998DC
2 changed files with 11 additions and 5 deletions

View File

@ -158,8 +158,9 @@ impl MDBook {
fn execute_build_process(&self, renderer: &Renderer) -> Result<()> { fn execute_build_process(&self, renderer: &Renderer) -> Result<()> {
let mut preprocessed_book = self.book.clone(); let mut preprocessed_book = self.book.clone();
let preprocess_ctx = let preprocess_ctx = PreprocessorContext::new(self.root.clone(),
PreprocessorContext::new(self.root.clone(), self.config.clone()); self.config.clone(),
renderer.name().to_string());
for preprocessor in &self.preprocessors { for preprocessor in &self.preprocessors {
debug!("Running the {} preprocessor.", preprocessor.name()); debug!("Running the {} preprocessor.", preprocessor.name());
@ -227,7 +228,10 @@ impl MDBook {
let temp_dir = TempFileBuilder::new().prefix("mdbook-").tempdir()?; let temp_dir = TempFileBuilder::new().prefix("mdbook-").tempdir()?;
let preprocess_context = PreprocessorContext::new(self.root.clone(), self.config.clone()); // FIXME: Is "test" the proper renderer name to use here?
let preprocess_context = PreprocessorContext::new(self.root.clone(),
self.config.clone(),
"test".to_string());
let book = LinkPreprocessor::new().run(&preprocess_context, self.book.clone())?; let book = LinkPreprocessor::new().run(&preprocess_context, self.book.clone())?;
// Index Preprocessor is disabled so that chapter paths continue to point to the // Index Preprocessor is disabled so that chapter paths continue to point to the

View File

@ -19,12 +19,14 @@ pub struct PreprocessorContext {
pub root: PathBuf, pub root: PathBuf,
/// The book configuration (`book.toml`). /// The book configuration (`book.toml`).
pub config: Config, pub config: Config,
/// The `Renderer` this preprocessor is being used with.
pub renderer: String,
} }
impl PreprocessorContext { impl PreprocessorContext {
/// Create a new `PreprocessorContext`. /// Create a new `PreprocessorContext`.
pub(crate) fn new(root: PathBuf, config: Config) -> Self { pub(crate) fn new(root: PathBuf, config: Config, renderer: String) -> Self {
PreprocessorContext { root, config } PreprocessorContext { root, config, renderer }
} }
} }