1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#![allow(unused)]
use mdbook::book::Book;
use mdbook::errors;
use mdbook::preprocess::{Preprocessor, PreprocessorContext};
use std::result;
use crate::theme::{CssFile, Item, Value};
macro_rules! default {
($idt:ident, $e1:expr) => { (CssFile::$idt, $e1) };
($idt:ident, $e1:expr, $e2:expr) => { (CssFile::$idt, Item($e1), Value($e2)) };
($($e1:expr, $idt:ident);*) => {
$(pub static $idt: &[u8] = include_bytes!($e1);)*
pub static ACE_DEFAULT: &[(&str, &[u8])] = &[$(($e1, $idt),)*];
};
}
pub mod ace;
pub mod theme;
#[derive(Debug)]
pub enum Error {
StrNotFound,
FileNotFound,
FileNotCreated,
FileNotWritten,
DirNotCreated,
DirNotRemoved,
DirNotRead,
AceNotFound,
MdbookNotParsed,
DeserializedFailed,
}
pub type Result<T> = std::result::Result<T, Error>;
pub struct PreTheme;
impl Preprocessor for PreTheme {
fn name(&self) -> &str { "theme" }
fn run(&self, ctx: &PreprocessorContext, book: Book) -> result::Result<Book, errors::Error> {
let dir = ctx.config.get("output.html.theme").map_or("theme", |s| s.as_str().unwrap());
if let Some(theme) = ctx.config.get_preprocessor(self.name()) {
theme::config::run(theme, dir);
}
Ok(book)
}
fn supports_renderer(&self, renderer: &str) -> bool { renderer == "html" }
}