"#,
before = before,
classes = classes,
- after = after)
- }).into_owned()
+ after = after
+ )
+ })
+ .into_owned()
}
fn add_playpen_pre(html: &str, playpen_config: &Playpen) -> String {
let regex = Regex::new(r##"((?s)]?class="([^"]+)".*?>(.*?)
)"##).unwrap();
- regex.replace_all(html, |caps: &Captures| {
- let text = &caps[1];
- let classes = &caps[2];
- let code = &caps[3];
+ regex
+ .replace_all(html, |caps: &Captures| {
+ let text = &caps[1];
+ let classes = &caps[2];
+ let code = &caps[3];
- if (classes.contains("language-rust") && !classes.contains("ignore")) ||
- classes.contains("mdbook-runnable")
- {
- // wrap the contents in an external pre block
- if playpen_config.editable && classes.contains("editable") ||
- text.contains("fn main") || text.contains("quick_main!")
+ if (classes.contains("language-rust") && !classes.contains("ignore"))
+ || classes.contains("mdbook-runnable")
{
- format!("{}
", text)
- } else {
- // we need to inject our own main
- let (attrs, code) = partition_source(code);
+ // wrap the contents in an external pre block
+ if playpen_config.editable && classes.contains("editable")
+ || text.contains("fn main") || text.contains("quick_main!")
+ {
+ format!("{}
", text)
+ } else {
+ // we need to inject our own main
+ let (attrs, code) = partition_source(code);
- format!("\n# \
- #![allow(unused_variables)]\n\
- {}#fn main() {{\n\
- {}\
- #}}
",
- classes,
- attrs,
- code)
+ format!(
+ "\n# \
+ #![allow(unused_variables)]\n{}#fn main() {{\n{}#}}
",
+ classes, attrs, code
+ )
+ }
+ } else {
+ // not language-rust, so no-op
+ text.to_owned()
}
- } else {
- // not language-rust, so no-op
- text.to_owned()
- }
- }).into_owned()
+ })
+ .into_owned()
}
fn partition_source(s: &str) -> (String, String) {
diff --git a/tests/rendered_output.rs b/tests/rendered_output.rs
index bdb786f0..3b3938d0 100644
--- a/tests/rendered_output.rs
+++ b/tests/rendered_output.rs
@@ -18,7 +18,7 @@ use select::document::Document;
use select::predicate::{Class, Name, Predicate};
use tempfile::Builder as TempFileBuilder;
use mdbook::errors::*;
-use mdbook::utils::fs::file_to_string;
+use mdbook::utils::fs::{file_to_string, write_file};
use mdbook::config::Config;
use mdbook::MDBook;
@@ -370,6 +370,24 @@ fn by_default_mdbook_use_index_preprocessor_to_convert_readme_to_index() {
assert_doesnt_contain_strings(&second_index, &unexpected_strings);
}
+#[test]
+fn theme_dir_overrides_work_correctly() {
+ let book_dir = dummy_book::new_copy_of_example_book().unwrap();
+ let book_dir = book_dir.path();
+ let theme_dir = book_dir.join("theme");
+
+ let mut index = ::mdbook::theme::INDEX.to_vec();
+ index.extend_from_slice(b"\n");
+
+ write_file(&theme_dir, "index.hbs", &index).unwrap();
+
+ let md = MDBook::load(book_dir).unwrap();
+ md.build().unwrap();
+
+ let built_index = book_dir.join("book").join("index.html");
+ dummy_book::assert_contains_strings(built_index, &["This is a modified index.hbs!"]);
+}
+
#[cfg(feature = "search")]
mod search {
extern crate serde_json;