Make MathJax support optional
to enable add following to book.toml ```toml [output.html] mathjax-support = true ```
This commit is contained in:
parent
b441066105
commit
f214c7108f
|
@ -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<String> {
|
||||
if let Some(htmlconfig) = self.config.get_html_config() {
|
||||
return htmlconfig.get_google_analytics_id();
|
||||
|
|
|
@ -7,6 +7,7 @@ pub struct HtmlConfig {
|
|||
destination: PathBuf,
|
||||
theme: PathBuf,
|
||||
curly_quotes: bool,
|
||||
mathjax_support: bool,
|
||||
google_analytics: Option<String>,
|
||||
additional_css: Vec<PathBuf>,
|
||||
additional_js: Vec<PathBuf>,
|
||||
|
@ -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<String> {
|
||||
self.google_analytics.clone()
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ pub struct TomlHtmlConfig {
|
|||
pub theme: Option<PathBuf>,
|
||||
pub google_analytics: Option<String>,
|
||||
pub curly_quotes: Option<bool>,
|
||||
pub mathjax_support: Option<bool>,
|
||||
pub additional_css: Option<Vec<PathBuf>>,
|
||||
pub additional_js: Option<Vec<PathBuf>>,
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
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();
|
||||
|
|
|
@ -27,8 +27,10 @@
|
|||
<link rel="stylesheet" href="{{this}}">
|
||||
{{/each}}
|
||||
|
||||
{{#if mathjax_support}}
|
||||
<!-- MathJax -->
|
||||
<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 -->
|
||||
<script src="https://cdn.jsdelivr.net/clipboard.js/1.6.1/clipboard.min.js"></script>
|
||||
|
|
Loading…
Reference in New Issue