#mdbook #boilerplate #proprocessor

mdbook-preprocessor-boilerplate

Boilerplate code for mdbook preprocessors

4 releases

Uses new Rust 2024

0.2.0 Jan 15, 2026
0.1.2 Apr 20, 2023
0.1.1 Dec 2, 2021
0.1.0 Dec 2, 2021

#862 in Text processing

Download history 2093/week @ 2025-10-20 3079/week @ 2025-10-27 2472/week @ 2025-11-03 1458/week @ 2025-11-10 2723/week @ 2025-11-17 2278/week @ 2025-11-24 1789/week @ 2025-12-01 1143/week @ 2025-12-08 406/week @ 2025-12-15 513/week @ 2025-12-22 675/week @ 2025-12-29 821/week @ 2026-01-05 806/week @ 2026-01-12 955/week @ 2026-01-19 159/week @ 2026-01-26 278/week @ 2026-02-02

2,305 downloads per month
Used in 2 crates

GPL-3.0 license

18KB

mdbook-preprocessor-boilerplate

Boilerplate code for mdbook preprocessors.

Handles the CLI, checks whether the renderer is supported, checks the mdbook version, and runs your preprocessor. All you need to do is implement the mdbook_preprocessor::Preprocessor trait.

Example

The following is functionally identical to the No-Op Preprocessor Example given by mdbook.

use mdbook_preprocessor::{book::Book, Preprocessor, PreprocessorContext};
use anyhow::{bail, Result};

fn main() -> Result<()> {
    mdbook_preprocessor_boilerplate::run(
        NoOpPreprocessor,
        "An mdbook preprocessor that does nothing" // CLI description
    )
}

struct NoOpPreprocessor;

impl Preprocessor for NoOpPreprocessor {
    fn name(&self) -> &str {
        "nop-preprocessor"
    }

    fn run(&self, ctx: &PreprocessorContext, book: Book) -> Result<Book> {
        // In testing we want to tell the preprocessor to blow up by setting a
        // particular config value
        if let Ok(Some(true)) = ctx.config.get(&format!("{}.blow-up", self.name())) {
            anyhow::bail!("Boom!!1!");
        }

        // we *are* a no-op preprocessor after all
        Ok(book)
    }

    fn supports_renderer(&self, renderer: &str) -> Result<bool> {
        Ok(renderer != "not-supported")
    }
}

License: GPL-3.0

Dependencies

~9–13MB
~157K SLoC