fifthtry_mdbook/preprocess/
mod.rs1pub 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 std::cell::RefCell;
16use std::collections::HashMap;
17use std::path::PathBuf;
18
19#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
22pub struct PreprocessorContext {
23 pub root: PathBuf,
25 pub config: Config,
27 pub renderer: String,
29 pub mdbook_version: String,
31 #[serde(skip)]
32 pub(crate) chapter_titles: RefCell<HashMap<PathBuf, String>>,
33 #[serde(skip)]
34 __non_exhaustive: (),
35}
36
37impl PreprocessorContext {
38 pub fn new(root: PathBuf, config: Config, renderer: String) -> Self {
40 PreprocessorContext {
41 root,
42 config,
43 renderer,
44 mdbook_version: crate::MDBOOK_VERSION.to_string(),
45 chapter_titles: RefCell::new(HashMap::new()),
46 __non_exhaustive: (),
47 }
48 }
49}
50
51pub trait Preprocessor {
54 fn name(&self) -> &str;
56
57 fn run(&self, ctx: &PreprocessorContext, book: Book) -> Result<Book>;
60
61 fn supports_renderer(&self, _renderer: &str) -> bool {
66 true
67 }
68}