The example preprocessor works

This commit is contained in:
Michael Bryan 2018-09-16 23:28:01 +08:00
parent 1aa1194d79
commit 1d72cea972
No known key found for this signature in database
GPG Key ID: E9C602B0D9A998DC
3 changed files with 8 additions and 3 deletions

View File

@ -1,9 +1,10 @@
extern crate mdbook; extern crate mdbook;
extern crate serde_json;
#[macro_use] #[macro_use]
extern crate clap; extern crate clap;
use clap::{App, Arg, ArgMatches, SubCommand}; use clap::{App, Arg, ArgMatches, SubCommand};
use mdbook::preprocess::{Preprocessor, PreprocessorContext, CmdPreprocessor}; use mdbook::preprocess::CmdPreprocessor;
use std::process; use std::process;
use std::io; use std::io;
@ -21,6 +22,8 @@ fn handle_preprocessing(args: &ArgMatches) {
let (ctx, book) = CmdPreprocessor::parse_input(io::stdin()) let (ctx, book) = CmdPreprocessor::parse_input(io::stdin())
.expect("Couldn't parse the input"); .expect("Couldn't parse the input");
eprintln!("{:?}", ctx.config);
// You can tell the preprocessor to blow up by setting a particular // You can tell the preprocessor to blow up by setting a particular
// config value // config value
if let Some(table) = ctx.config.get_preprocessor("nop-preprocessor") { if let Some(table) = ctx.config.get_preprocessor("nop-preprocessor") {
@ -30,6 +33,8 @@ fn handle_preprocessing(args: &ArgMatches) {
panic!("Boom!!!1!"); panic!("Boom!!!1!");
} }
} }
serde_json::to_writer(io::stdout(), &book).unwrap();
} }
fn handle_supports(sub_args: &ArgMatches) { fn handle_supports(sub_args: &ArgMatches) {

View File

@ -105,7 +105,7 @@ impl Preprocessor for CmdPreprocessor {
Ok(c) => c, Ok(c) => c,
Err(e) => { Err(e) => {
warn!("Unable to create the command for the \"{}\" preprocessor, {}", self.name(), e); warn!("Unable to create the command for the \"{}\" preprocessor, {}", self.name(), e);
return true; return false;
} }
}; };

View File

@ -32,7 +32,7 @@ fn ask_the_preprocessor_to_blow_up() {
let mut md = MDBook::load(&dummy_book).unwrap(); let mut md = MDBook::load(&dummy_book).unwrap();
md.with_preprecessor(example()); 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(); let got = md.build();