From 53668b8719e9c799c30f367f9171f2d40ce671ed Mon Sep 17 00:00:00 2001 From: Manuel Cillero Date: Tue, 26 Jul 2022 06:31:00 +0200 Subject: [PATCH] Elimina el directorio examples de mdbook --- .../doc/src/for_developers/preprocessors.md | 8 -- website/examples/nop-preprocessor.rs | 104 ------------------ 2 files changed, 112 deletions(-) delete mode 100644 website/examples/nop-preprocessor.rs diff --git a/website/doc/src/for_developers/preprocessors.md b/website/doc/src/for_developers/preprocessors.md index 1ac46256..dbe78779 100644 --- a/website/doc/src/for_developers/preprocessors.md +++ b/website/doc/src/for_developers/preprocessors.md @@ -33,14 +33,6 @@ translates inputs to the correct `Preprocessor` method. For convenience, there is [an example no-op preprocessor] in the `examples/` directory which can easily be adapted for other preprocessors. -
-Example no-op preprocessor - -```rust -// nop-preprocessors.rs - -{{#include ../../../examples/nop-preprocessor.rs}} -```
## Hints For Implementing A Preprocessor diff --git a/website/examples/nop-preprocessor.rs b/website/examples/nop-preprocessor.rs deleted file mode 100644 index ace40093..00000000 --- a/website/examples/nop-preprocessor.rs +++ /dev/null @@ -1,104 +0,0 @@ -use crate::nop_lib::Nop; -use clap::{App, Arg, ArgMatches}; -use mdbook::book::Book; -use mdbook::errors::Error; -use mdbook::preprocess::{CmdPreprocessor, Preprocessor, PreprocessorContext}; -use semver::{Version, VersionReq}; -use std::io; -use std::process; - -pub fn make_app() -> App<'static> { - App::new("nop-preprocessor") - .about("A mdbook preprocessor which does precisely nothing") - .subcommand( - App::new("supports") - .arg(Arg::new("renderer").required(true)) - .about("Check whether a renderer is supported by this preprocessor"), - ) -} - -fn main() { - let matches = make_app().get_matches(); - - // Users will want to construct their own preprocessor here - let preprocessor = Nop::new(); - - if let Some(sub_args) = matches.subcommand_matches("supports") { - handle_supports(&preprocessor, sub_args); - } else if let Err(e) = handle_preprocessing(&preprocessor) { - eprintln!("{}", e); - process::exit(1); - } -} - -fn handle_preprocessing(pre: &dyn Preprocessor) -> Result<(), Error> { - let (ctx, book) = CmdPreprocessor::parse_input(io::stdin())?; - - let book_version = Version::parse(&ctx.mdbook_version)?; - let version_req = VersionReq::parse(mdbook::MDBOOK_VERSION)?; - - if !version_req.matches(&book_version) { - eprintln!( - "Warning: The {} plugin was built against version {} of mdbook, \ - but we're being called from version {}", - pre.name(), - mdbook::MDBOOK_VERSION, - ctx.mdbook_version - ); - } - - let processed_book = pre.run(&ctx, book)?; - serde_json::to_writer(io::stdout(), &processed_book)?; - - Ok(()) -} - -fn handle_supports(pre: &dyn Preprocessor, sub_args: &ArgMatches) -> ! { - let renderer = sub_args.value_of("renderer").expect("Required argument"); - let supported = pre.supports_renderer(renderer); - - // Signal whether the renderer is supported by exiting with 1 or 0. - if supported { - process::exit(0); - } else { - process::exit(1); - } -} - -/// The actual implementation of the `Nop` preprocessor. This would usually go -/// in your main `lib.rs` file. -mod nop_lib { - use super::*; - - /// A no-op preprocessor. - pub struct Nop; - - impl Nop { - pub fn new() -> Nop { - Nop - } - } - - impl Preprocessor for Nop { - fn name(&self) -> &str { - "nop-preprocessor" - } - - fn run(&self, ctx: &PreprocessorContext, book: Book) -> Result { - // In testing we want to tell the preprocessor to blow up by setting a - // particular config value - if let Some(nop_cfg) = ctx.config.get_preprocessor(self.name()) { - if nop_cfg.contains_key("blow-up") { - anyhow::bail!("Boom!!1!"); - } - } - - // we *are* a no-op preprocessor after all - Ok(book) - } - - fn supports_renderer(&self, renderer: &str) -> bool { - renderer != "not-supported" - } - } -}