Run rustfmt.
This commit is contained in:
parent
991a725c26
commit
742dbbc917
|
@ -56,10 +56,7 @@ where
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_emphasis(
|
fn remove_emphasis(num_removed_items: &mut usize, chapter: &mut Chapter) -> Result<String> {
|
||||||
num_removed_items: &mut usize,
|
|
||||||
chapter: &mut Chapter,
|
|
||||||
) -> Result<String> {
|
|
||||||
let mut buf = String::with_capacity(chapter.content.len());
|
let mut buf = String::with_capacity(chapter.content.len());
|
||||||
|
|
||||||
let events = Parser::new(&chapter.content).filter(|e| {
|
let events = Parser::new(&chapter.content).filter(|e| {
|
||||||
|
@ -76,7 +73,7 @@ fn remove_emphasis(
|
||||||
should_keep
|
should_keep
|
||||||
});
|
});
|
||||||
|
|
||||||
cmark(events, &mut buf, None).map(|_| buf).map_err(|err| {
|
cmark(events, &mut buf, None)
|
||||||
Error::from(format!("Markdown serialization failed: {}", err))
|
.map(|_| buf)
|
||||||
})
|
.map_err(|err| Error::from(format!("Markdown serialization failed: {}", err)))
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,9 @@ use clap::{App, Arg, ArgMatches, SubCommand};
|
||||||
use mdbook::book::Book;
|
use mdbook::book::Book;
|
||||||
use mdbook::errors::Error;
|
use mdbook::errors::Error;
|
||||||
use mdbook::preprocess::{CmdPreprocessor, Preprocessor, PreprocessorContext};
|
use mdbook::preprocess::{CmdPreprocessor, Preprocessor, PreprocessorContext};
|
||||||
|
use nop_lib::Nop;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::process;
|
use std::process;
|
||||||
use nop_lib::Nop;
|
|
||||||
|
|
||||||
pub fn make_app() -> App<'static, 'static> {
|
pub fn make_app() -> App<'static, 'static> {
|
||||||
App::new("nop-preprocessor")
|
App::new("nop-preprocessor")
|
||||||
|
@ -16,7 +16,8 @@ pub fn make_app() -> App<'static, 'static> {
|
||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name("supports")
|
SubCommand::with_name("supports")
|
||||||
.arg(Arg::with_name("renderer").required(true))
|
.arg(Arg::with_name("renderer").required(true))
|
||||||
.about("Check whether a renderer is supported by this preprocessor"))
|
.about("Check whether a renderer is supported by this preprocessor"),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -87,11 +88,7 @@ mod nop_lib {
|
||||||
"nop-preprocessor"
|
"nop-preprocessor"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(
|
fn run(&self, ctx: &PreprocessorContext, book: Book) -> Result<Book, Error> {
|
||||||
&self,
|
|
||||||
ctx: &PreprocessorContext,
|
|
||||||
book: Book,
|
|
||||||
) -> Result<Book, Error> {
|
|
||||||
// In testing we want to tell the preprocessor to blow up by setting a
|
// In testing we want to tell the preprocessor to blow up by setting a
|
||||||
// particular config value
|
// particular config value
|
||||||
if let Some(nop_cfg) = ctx.config.get_preprocessor(self.name()) {
|
if let Some(nop_cfg) = ctx.config.get_preprocessor(self.name()) {
|
||||||
|
@ -109,4 +106,3 @@ mod nop_lib {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,9 +12,10 @@ pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
|
||||||
SubCommand::with_name("init")
|
SubCommand::with_name("init")
|
||||||
.about("Creates the boilerplate structure and files for a new book")
|
.about("Creates the boilerplate structure and files for a new book")
|
||||||
// the {n} denotes a newline which will properly aligned in all help messages
|
// the {n} denotes a newline which will properly aligned in all help messages
|
||||||
.arg_from_usage("[dir] 'Directory to create the book in{n}\
|
.arg_from_usage(
|
||||||
(Defaults to the Current Directory when omitted)'")
|
"[dir] 'Directory to create the book in{n}\
|
||||||
.arg_from_usage("--theme 'Copies the default theme into your source folder'")
|
(Defaults to the Current Directory when omitted)'",
|
||||||
|
).arg_from_usage("--theme 'Copies the default theme into your source folder'")
|
||||||
.arg_from_usage("--force 'Skips confirmation prompts'")
|
.arg_from_usage("--force 'Skips confirmation prompts'")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,19 +43,11 @@ impl CmdPreprocessor {
|
||||||
|
|
||||||
/// A convenience function custom preprocessors can use to parse the input
|
/// A convenience function custom preprocessors can use to parse the input
|
||||||
/// written to `stdin` by a `CmdRenderer`.
|
/// written to `stdin` by a `CmdRenderer`.
|
||||||
pub fn parse_input<R: Read>(
|
pub fn parse_input<R: Read>(reader: R) -> Result<(PreprocessorContext, Book)> {
|
||||||
reader: R,
|
serde_json::from_reader(reader).chain_err(|| "Unable to parse the input")
|
||||||
) -> Result<(PreprocessorContext, Book)> {
|
|
||||||
serde_json::from_reader(reader)
|
|
||||||
.chain_err(|| "Unable to parse the input")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_input_to_child(
|
fn write_input_to_child(&self, child: &mut Child, book: &Book, ctx: &PreprocessorContext) {
|
||||||
&self,
|
|
||||||
child: &mut Child,
|
|
||||||
book: &Book,
|
|
||||||
ctx: &PreprocessorContext,
|
|
||||||
) {
|
|
||||||
let stdin = child.stdin.take().expect("Child has stdin");
|
let stdin = child.stdin.take().expect("Child has stdin");
|
||||||
|
|
||||||
if let Err(e) = self.write_input(stdin, &book, &ctx) {
|
if let Err(e) = self.write_input(stdin, &book, &ctx) {
|
||||||
|
@ -128,8 +120,7 @@ impl Preprocessor for CmdPreprocessor {
|
||||||
"The preprocessor exited unsuccessfully"
|
"The preprocessor exited unsuccessfully"
|
||||||
);
|
);
|
||||||
|
|
||||||
serde_json::from_slice(&output.stdout)
|
serde_json::from_slice(&output.stdout).chain_err(|| "Unable to parse the preprocessed book")
|
||||||
.chain_err(|| "Unable to parse the preprocessed book")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn supports_renderer(&self, renderer: &str) -> bool {
|
fn supports_renderer(&self, renderer: &str) -> bool {
|
||||||
|
@ -142,7 +133,11 @@ impl Preprocessor for CmdPreprocessor {
|
||||||
let mut cmd = match self.command() {
|
let mut cmd = match self.command() {
|
||||||
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 false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -177,8 +172,7 @@ mod tests {
|
||||||
use MDBook;
|
use MDBook;
|
||||||
|
|
||||||
fn book_example() -> MDBook {
|
fn book_example() -> MDBook {
|
||||||
let example =
|
let example = Path::new(env!("CARGO_MANIFEST_DIR")).join("book-example");
|
||||||
Path::new(env!("CARGO_MANIFEST_DIR")).join("book-example");
|
|
||||||
MDBook::load(example).unwrap()
|
MDBook::load(example).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,8 +189,7 @@ mod tests {
|
||||||
let mut buffer = Vec::new();
|
let mut buffer = Vec::new();
|
||||||
cmd.write_input(&mut buffer, &md.book, &ctx).unwrap();
|
cmd.write_input(&mut buffer, &md.book, &ctx).unwrap();
|
||||||
|
|
||||||
let (got_ctx, got_book) =
|
let (got_ctx, got_book) = CmdPreprocessor::parse_input(buffer.as_slice()).unwrap();
|
||||||
CmdPreprocessor::parse_input(buffer.as_slice()).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(got_book, md.book);
|
assert_eq!(got_book, md.book);
|
||||||
assert_eq!(got_ctx, ctx);
|
assert_eq!(got_ctx, ctx);
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
//! Book preprocessing.
|
//! Book preprocessing.
|
||||||
|
|
||||||
|
pub use self::cmd::CmdPreprocessor;
|
||||||
pub use self::index::IndexPreprocessor;
|
pub use self::index::IndexPreprocessor;
|
||||||
pub use self::links::LinkPreprocessor;
|
pub use self::links::LinkPreprocessor;
|
||||||
pub use self::cmd::CmdPreprocessor;
|
|
||||||
|
|
||||||
|
mod cmd;
|
||||||
mod index;
|
mod index;
|
||||||
mod links;
|
mod links;
|
||||||
mod cmd;
|
|
||||||
|
|
||||||
use book::Book;
|
use book::Book;
|
||||||
use config::Config;
|
use config::Config;
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
pub mod navigation;
|
pub mod navigation;
|
||||||
|
pub mod theme;
|
||||||
pub mod toc;
|
pub mod toc;
|
||||||
pub mod theme;
|
|
|
@ -7,7 +7,10 @@ use mdbook::preprocess::{CmdPreprocessor, Preprocessor};
|
||||||
use mdbook::MDBook;
|
use mdbook::MDBook;
|
||||||
|
|
||||||
fn example() -> CmdPreprocessor {
|
fn example() -> CmdPreprocessor {
|
||||||
CmdPreprocessor::new("nop-preprocessor".to_string(), "cargo run --example nop-preprocessor --".to_string())
|
CmdPreprocessor::new(
|
||||||
|
"nop-preprocessor".to_string(),
|
||||||
|
"cargo run --example nop-preprocessor --".to_string(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -35,7 +38,9 @@ fn ask_the_preprocessor_to_blow_up() {
|
||||||
let mut md = MDBook::load(temp.path()).unwrap();
|
let mut md = MDBook::load(temp.path()).unwrap();
|
||||||
md.with_preprecessor(example());
|
md.with_preprecessor(example());
|
||||||
|
|
||||||
md.config.set("preprocessor.nop-preprocessor.blow-up", true).unwrap();
|
md.config
|
||||||
|
.set("preprocessor.nop-preprocessor.blow-up", true)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let got = md.build();
|
let got = md.build();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue