Skip to content

Commit 18a36ec

Browse files
Fixed the build.use-default-preprocessors flag
1 parent 40ede19 commit 18a36ec

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/book/mod.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -360,16 +360,20 @@ fn determine_preprocessors(config: &Config) -> Result<Vec<Box<Preprocessor>>> {
360360
.and_then(|value| value.as_table())
361361
.map(|table| table.keys());
362362

363+
let mut preprocessors = if config.build.use_default_preprocessors {
364+
default_preprocessors()
365+
} else {
366+
Vec::new()
367+
};
368+
363369
let preprocessor_keys = match preprocessor_keys {
364370
Some(keys) => keys,
365371
// If no preprocessor field is set, default to the LinkPreprocessor and
366372
// IndexPreprocessor. This allows you to disable default preprocessors
367373
// by setting "preprocess" to an empty list.
368-
None => return Ok(default_preprocessors()),
374+
None => return Ok(preprocessors),
369375
};
370376

371-
let mut preprocessors: Vec<Box<Preprocessor>> = Vec::new();
372-
373377
for key in preprocessor_keys {
374378
match key.as_ref() {
375379
"links" => preprocessors.push(Box::new(LinkPreprocessor::new())),
@@ -477,6 +481,16 @@ mod tests {
477481
assert_eq!(got.as_ref().unwrap()[1].name(), "index");
478482
}
479483

484+
#[test]
485+
fn use_default_preprocessors_works() {
486+
let mut cfg = Config::default();
487+
cfg.build.use_default_preprocessors = false;
488+
489+
let got = determine_preprocessors(&cfg).unwrap();
490+
491+
assert_eq!(got.len(), 0);
492+
}
493+
480494
#[test]
481495
fn config_complains_if_unimplemented_preprocessor() {
482496
let cfg_str: &'static str = r#"

src/config.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ mod tests {
564564
[build]
565565
build-dir = "outputs"
566566
create-missing = false
567-
preprocess = ["first_preprocessor", "second_preprocessor"]
567+
use-default-preprocessors = true
568568
569569
[output.html]
570570
theme = "./themedir"
@@ -575,6 +575,10 @@ mod tests {
575575
[output.html.playpen]
576576
editable = true
577577
editor = "ace"
578+
579+
[preprocess.first]
580+
581+
[preprocess.second]
578582
"#;
579583

580584
#[test]

0 commit comments

Comments
 (0)