From f214c7108fdefab0ef5e9857cf4e016621b0e1ae Mon Sep 17 00:00:00 2001 From: Michal Budzynski Date: Sun, 25 Jun 2017 00:32:26 +0200 Subject: [PATCH] Make MathJax support optional to enable add following to book.toml ```toml [output.html] mathjax-support = true ``` --- src/book/mod.rs | 17 +++++++++++++++++ src/config/htmlconfig.rs | 14 ++++++++++++++ src/config/tomlconfig.rs | 1 + src/renderer/html_handlebars/hbs_renderer.rs | 4 ++++ src/theme/index.hbs | 2 ++ 5 files changed, 38 insertions(+) diff --git a/src/book/mod.rs b/src/book/mod.rs index 35ed41f7..f33a9187 100644 --- a/src/book/mod.rs +++ b/src/book/mod.rs @@ -498,6 +498,23 @@ impl MDBook { false } + pub fn with_mathjax_support(mut self, mathjax_support: bool) -> Self { + if let Some(htmlconfig) = self.config.get_mut_html_config() { + htmlconfig.set_mathjax_support(mathjax_support); + } else { + error!("There is no HTML renderer set..."); + } + self + } + + pub fn get_mathjax_support(&self) -> bool { + if let Some(htmlconfig) = self.config.get_html_config() { + return htmlconfig.get_mathjax_support(); + } + + false + } + pub fn get_google_analytics_id(&self) -> Option { if let Some(htmlconfig) = self.config.get_html_config() { return htmlconfig.get_google_analytics_id(); diff --git a/src/config/htmlconfig.rs b/src/config/htmlconfig.rs index 0cb2192b..5d5cac94 100644 --- a/src/config/htmlconfig.rs +++ b/src/config/htmlconfig.rs @@ -7,6 +7,7 @@ pub struct HtmlConfig { destination: PathBuf, theme: PathBuf, curly_quotes: bool, + mathjax_support: bool, google_analytics: Option, additional_css: Vec, additional_js: Vec, @@ -30,6 +31,7 @@ impl HtmlConfig { destination: root.clone().join("book"), theme: root.join("theme"), curly_quotes: false, + mathjax_support: false, google_analytics: None, additional_css: Vec::new(), additional_js: Vec::new(), @@ -51,6 +53,10 @@ impl HtmlConfig { self.curly_quotes = curly_quotes; } + if let Some(mathjax_support) = tomlconfig.mathjax_support { + self.mathjax_support = mathjax_support; + } + if tomlconfig.google_analytics.is_some() { self.google_analytics = tomlconfig.google_analytics; } @@ -116,6 +122,14 @@ impl HtmlConfig { self.curly_quotes = curly_quotes; } + pub fn get_mathjax_support(&self) -> bool { + self.mathjax_support + } + + pub fn set_mathjax_support(&mut self, mathjax_support: bool) { + self.mathjax_support = mathjax_support; + } + pub fn get_google_analytics_id(&self) -> Option { self.google_analytics.clone() } diff --git a/src/config/tomlconfig.rs b/src/config/tomlconfig.rs index 90cfa4c6..5fac3a3e 100644 --- a/src/config/tomlconfig.rs +++ b/src/config/tomlconfig.rs @@ -25,6 +25,7 @@ pub struct TomlHtmlConfig { pub theme: Option, pub google_analytics: Option, pub curly_quotes: Option, + pub mathjax_support: Option, pub additional_css: Option>, pub additional_js: Option>, } diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index fd69ee58..34b240f2 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -318,6 +318,10 @@ fn make_data(book: &MDBook) -> Result data.insert("google_analytics".to_owned(), json!(ga)); } + if book.get_mathjax_support() { + data.insert("mathjax_support".to_owned(), json!(true)); + } + // Add check to see if there is an additional style if book.has_additional_css() { let mut css = Vec::new(); diff --git a/src/theme/index.hbs b/src/theme/index.hbs index 467d2fe6..769d1caa 100644 --- a/src/theme/index.hbs +++ b/src/theme/index.hbs @@ -27,8 +27,10 @@ {{/each}} + {{#if mathjax_support}} + {{/if}}