1pub use self::cmd::CmdPreprocessor;
4pub use self::index::IndexPreprocessor;
5pub use self::links::LinkPreprocessor;
6
7mod cmd;
8mod index;
9mod links;
10
11use crate::book::Book;
12use crate::config::Config;
13use crate::errors::*;
14
15use serde::{Deserialize, Serialize};
16use std::cell::RefCell;
17use std::collections::HashMap;
18use std::path::PathBuf;
19
20#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
23pub struct PreprocessorContext {
24 pub root: PathBuf,
26 pub config: Config,
28 pub renderer: String,
30 pub mdbook_version: String,
32 #[serde(skip)]
33 pub(crate) chapter_titles: RefCell<HashMap<PathBuf, String>>,
34 #[serde(skip)]
35 __non_exhaustive: (),
36}
37
38impl PreprocessorContext {
39 pub(crate) fn new(root: PathBuf, config: Config, renderer: String) -> Self {
41 PreprocessorContext {
42 root,
43 config,
44 renderer,
45 mdbook_version: crate::MDBOOK_VERSION.to_string(),
46 chapter_titles: RefCell::new(HashMap::new()),
47 __non_exhaustive: (),
48 }
49 }
50}
51
52pub trait Preprocessor {
55 fn name(&self) -> &str;
57
58 fn run(&self, ctx: &PreprocessorContext, book: Book) -> Result<Book>;
61
62 fn supports_renderer(&self, _renderer: &str) -> bool {
67 true
68 }
69}