Fix MathJax Integration

Signed-off-by: trivernis <trivernis@protonmail.com>
feature/epub-rendering
trivernis 4 years ago
parent b14ba1b647
commit 04e1e30fef
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

2
Cargo.lock generated

@ -1277,7 +1277,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "snekdown"
version = "0.29.0"
version = "0.29.1"
dependencies = [
"asciimath-rs 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)",
"base64 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)",

@ -1,6 +1,6 @@
[package]
name = "snekdown"
version = "0.29.0"
version = "0.29.1"
authors = ["trivernis <trivernis@protonmail.com>"]
edition = "2018"
license-file = "LICENSE"

@ -168,11 +168,15 @@ included-bibliography = ["mybib.toml"]
included-glossary = ["myglossary.toml"]
# if external sources (images, stylesheets, MathJax)
# should be embedded into the document (default true)
# should be embedded into the document (default: true)
embed-external = true
# If SmartArrows should be used (default true)
# If SmartArrows should be used (default: true)
smart-arrows = true
# Includes a MathJax script tag in the document to render MathML in chromium.
# (default: true)
include-math-jax = true
```
The `[Section]` keys are not relevant as the structure gets flattened before the values are read.

@ -1,7 +1,7 @@
use crate::elements::*;
use crate::format::html::html_writer::HTMLWriter;
use crate::format::PlaceholderTemplate;
use crate::references::configuration::keys::{EMBED_EXTERNAL, META_LANG};
use crate::references::configuration::keys::{EMBED_EXTERNAL, INCLUDE_MATHJAX, META_LANG};
use crate::references::configuration::Value;
use crate::references::glossary::{GlossaryDisplay, GlossaryReference};
use crate::references::templates::{Template, TemplateVariable};
@ -103,10 +103,6 @@ impl ToHtml for MetadataValue {
impl ToHtml for Document {
fn to_html(&self, writer: &mut HTMLWriter) -> io::Result<()> {
let downloads = Arc::clone(&self.downloads);
let mathjax = downloads
.lock()
.unwrap()
.add_download(MATHJAX_URL.to_string());
if let Some(Value::Bool(embed)) = self
.config
.get_entry(EMBED_EXTERNAL)
@ -138,17 +134,6 @@ impl ToHtml for Document {
writer.write(path)?;
writer.write("/>".to_string())?;
writer.write("<meta charset=\"UTF-8\">".to_string())?;
if let Some(data) = std::mem::replace(&mut mathjax.lock().unwrap().data, None) {
writer.write("<script id=\"MathJax-script\">".to_string())?;
writer.write_escaped(minify(String::from_utf8(data).unwrap().as_str()))?;
writer.write("</script>".to_string())?;
} else {
writer.write(format!(
"<script id=\"MathJax-script\" async src={}></script>",
MATHJAX_URL
))?;
}
writer.write("<style>".to_string())?;
writer.write(style)?;
writer.write("</style>".to_string())?;
@ -157,6 +142,17 @@ impl ToHtml for Document {
let mut stylesheet = stylesheet.lock().unwrap();
let data = std::mem::replace(&mut stylesheet.data, None);
if let Some(data) = data {
if self
.config
.get_entry(INCLUDE_MATHJAX)
.and_then(|e| e.get().as_bool())
.unwrap_or(true)
{
writer.write(format!(
"<script id=\"MathJax-script\" type=\"text/javascript\" async src={}></script>",
MATHJAX_URL
))?;
}
writer.write("<style>".to_string())?;
writer.write(minify(String::from_utf8(data).unwrap().as_str()))?;
writer.write("</style>".to_string())?;

@ -8,3 +8,4 @@ pub const IMP_BIBLIOGRAPHY: &str = "included-bibliography";
pub const IMP_GLOSSARY: &str = "included-glossary";
pub const EMBED_EXTERNAL: &str = "embed-external";
pub const SMART_ARROWS: &str = "smart-arrows";
pub const INCLUDE_MATHJAX: &str = "include-math-jax";

Loading…
Cancel
Save