diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs
index fbaad523..4341ce3b 100644
--- a/src/renderer/html_handlebars/hbs_renderer.rs
+++ b/src/renderer/html_handlebars/hbs_renderer.rs
@@ -273,7 +273,7 @@ impl Renderer for HtmlHandlebars {
let theme_dir = match html_config.theme {
Some(ref theme) => theme.to_path_buf(),
- None => src_dir.join("theme"),
+ None => ctx.root.join("theme"),
};
let theme = theme::Theme::new(theme_dir);
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;