Fixed the `build.use-default-preprocessors` flag
This commit is contained in:
parent
40ede19103
commit
18a36ec1fa
|
@ -360,16 +360,20 @@ fn determine_preprocessors(config: &Config) -> Result<Vec<Box<Preprocessor>>> {
|
|||
.and_then(|value| value.as_table())
|
||||
.map(|table| table.keys());
|
||||
|
||||
let mut preprocessors = if config.build.use_default_preprocessors {
|
||||
default_preprocessors()
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
|
||||
let preprocessor_keys = match preprocessor_keys {
|
||||
Some(keys) => keys,
|
||||
// If no preprocessor field is set, default to the LinkPreprocessor and
|
||||
// IndexPreprocessor. This allows you to disable default preprocessors
|
||||
// by setting "preprocess" to an empty list.
|
||||
None => return Ok(default_preprocessors()),
|
||||
None => return Ok(preprocessors),
|
||||
};
|
||||
|
||||
let mut preprocessors: Vec<Box<Preprocessor>> = Vec::new();
|
||||
|
||||
for key in preprocessor_keys {
|
||||
match key.as_ref() {
|
||||
"links" => preprocessors.push(Box::new(LinkPreprocessor::new())),
|
||||
|
@ -477,6 +481,16 @@ mod tests {
|
|||
assert_eq!(got.as_ref().unwrap()[1].name(), "index");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn use_default_preprocessors_works() {
|
||||
let mut cfg = Config::default();
|
||||
cfg.build.use_default_preprocessors = false;
|
||||
|
||||
let got = determine_preprocessors(&cfg).unwrap();
|
||||
|
||||
assert_eq!(got.len(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn config_complains_if_unimplemented_preprocessor() {
|
||||
let cfg_str: &'static str = r#"
|
||||
|
|
|
@ -564,7 +564,7 @@ mod tests {
|
|||
[build]
|
||||
build-dir = "outputs"
|
||||
create-missing = false
|
||||
preprocess = ["first_preprocessor", "second_preprocessor"]
|
||||
use-default-preprocessors = true
|
||||
|
||||
[output.html]
|
||||
theme = "./themedir"
|
||||
|
@ -575,6 +575,10 @@ mod tests {
|
|||
[output.html.playpen]
|
||||
editable = true
|
||||
editor = "ace"
|
||||
|
||||
[preprocess.first]
|
||||
|
||||
[preprocess.second]
|
||||
"#;
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in New Issue