Skip to content

Commit

Permalink
The example preprocessor works
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-F-Bryan committed Sep 16, 2018
1 parent 1aa1194 commit 1d72cea
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion examples/nop-preprocessor.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
extern crate mdbook;
extern crate serde_json;
#[macro_use]
extern crate clap;

use clap::{App, Arg, ArgMatches, SubCommand};
use mdbook::preprocess::{Preprocessor, PreprocessorContext, CmdPreprocessor};
use mdbook::preprocess::CmdPreprocessor;
use std::process;
use std::io;

Expand All @@ -21,6 +22,8 @@ fn handle_preprocessing(args: &ArgMatches) {
let (ctx, book) = CmdPreprocessor::parse_input(io::stdin())
.expect("Couldn't parse the input");

eprintln!("{:?}", ctx.config);

// You can tell the preprocessor to blow up by setting a particular
// config value
if let Some(table) = ctx.config.get_preprocessor("nop-preprocessor") {
Expand All @@ -30,6 +33,8 @@ fn handle_preprocessing(args: &ArgMatches) {
panic!("Boom!!!1!");
}
}

serde_json::to_writer(io::stdout(), &book).unwrap();
}

fn handle_supports(sub_args: &ArgMatches) {
Expand Down
2 changes: 1 addition & 1 deletion src/preprocess/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl Preprocessor for CmdPreprocessor {
Ok(c) => c,
Err(e) => {
warn!("Unable to create the command for the \"{}\" preprocessor, {}", self.name(), e);
return true;
return false;
}
};

Expand Down
2 changes: 1 addition & 1 deletion tests/custom_preprocessors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn ask_the_preprocessor_to_blow_up() {
let mut md = MDBook::load(&dummy_book).unwrap();
md.with_preprecessor(example());

md.config.set("preprocess.nop-preprocessor.blow-up", true).unwrap();
md.config.set("preprocessor.nop-preprocessor.blow-up", true).unwrap();

let got = md.build();

Expand Down

0 comments on commit 1d72cea

Please sign in to comment.