Make MathJax support optional

to enable add following to book.toml
```toml
[output.html]
mathjax-support = true
```
This commit is contained in:
Michal Budzynski 2017-06-25 00:32:26 +02:00
parent b441066105
commit f214c7108f
5 changed files with 38 additions and 0 deletions

View File

@ -498,6 +498,23 @@ impl MDBook {
false 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<String> { pub fn get_google_analytics_id(&self) -> Option<String> {
if let Some(htmlconfig) = self.config.get_html_config() { if let Some(htmlconfig) = self.config.get_html_config() {
return htmlconfig.get_google_analytics_id(); return htmlconfig.get_google_analytics_id();

View File

@ -7,6 +7,7 @@ pub struct HtmlConfig {
destination: PathBuf, destination: PathBuf,
theme: PathBuf, theme: PathBuf,
curly_quotes: bool, curly_quotes: bool,
mathjax_support: bool,
google_analytics: Option<String>, google_analytics: Option<String>,
additional_css: Vec<PathBuf>, additional_css: Vec<PathBuf>,
additional_js: Vec<PathBuf>, additional_js: Vec<PathBuf>,
@ -30,6 +31,7 @@ impl HtmlConfig {
destination: root.clone().join("book"), destination: root.clone().join("book"),
theme: root.join("theme"), theme: root.join("theme"),
curly_quotes: false, curly_quotes: false,
mathjax_support: false,
google_analytics: None, google_analytics: None,
additional_css: Vec::new(), additional_css: Vec::new(),
additional_js: Vec::new(), additional_js: Vec::new(),
@ -51,6 +53,10 @@ impl HtmlConfig {
self.curly_quotes = curly_quotes; self.curly_quotes = curly_quotes;
} }
if let Some(mathjax_support) = tomlconfig.mathjax_support {
self.mathjax_support = mathjax_support;
}
if tomlconfig.google_analytics.is_some() { if tomlconfig.google_analytics.is_some() {
self.google_analytics = tomlconfig.google_analytics; self.google_analytics = tomlconfig.google_analytics;
} }
@ -116,6 +122,14 @@ impl HtmlConfig {
self.curly_quotes = curly_quotes; 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<String> { pub fn get_google_analytics_id(&self) -> Option<String> {
self.google_analytics.clone() self.google_analytics.clone()
} }

View File

@ -25,6 +25,7 @@ pub struct TomlHtmlConfig {
pub theme: Option<PathBuf>, pub theme: Option<PathBuf>,
pub google_analytics: Option<String>, pub google_analytics: Option<String>,
pub curly_quotes: Option<bool>, pub curly_quotes: Option<bool>,
pub mathjax_support: Option<bool>,
pub additional_css: Option<Vec<PathBuf>>, pub additional_css: Option<Vec<PathBuf>>,
pub additional_js: Option<Vec<PathBuf>>, pub additional_js: Option<Vec<PathBuf>>,
} }

View File

@ -318,6 +318,10 @@ fn make_data(book: &MDBook) -> Result<serde_json::Map<String, serde_json::Value>
data.insert("google_analytics".to_owned(), json!(ga)); 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 // Add check to see if there is an additional style
if book.has_additional_css() { if book.has_additional_css() {
let mut css = Vec::new(); let mut css = Vec::new();

View File

@ -27,8 +27,10 @@
<link rel="stylesheet" href="{{this}}"> <link rel="stylesheet" href="{{this}}">
{{/each}} {{/each}}
{{#if mathjax_support}}
<!-- MathJax --> <!-- MathJax -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
{{/if}}
<!-- Fetch Clipboard.js from CDN but have a local fallback --> <!-- Fetch Clipboard.js from CDN but have a local fallback -->
<script src="https://cdn.jsdelivr.net/clipboard.js/1.6.1/clipboard.min.js"></script> <script src="https://cdn.jsdelivr.net/clipboard.js/1.6.1/clipboard.min.js"></script>