Add option to turn off embedding of images

Signed-off-by: trivernis <trivernis@protonmail.com>
feature/epub-rendering
trivernis 4 years ago
parent 2dba1025e8
commit 9424d04c37
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.27.1"
version = "0.27.2"
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.27.1"
version = "0.27.2"
authors = ["trivernis <trivernis@protonmail.com>"]
edition = "2018"
license-file = "LICENSE"

@ -46,7 +46,8 @@ Extended syntax with metadata and no description
!(url)[metadata]
```
When generating the html file the images are base64 embedded.
When generating the html file the images are base64 embedded. To turn off this behaviour
set the config parameter `embed-external` to `false`.
### Quotes

@ -1,7 +1,8 @@
use crate::elements::*;
use crate::format::html::html_writer::HTMLWriter;
use crate::format::PlaceholderTemplate;
use crate::references::configuration::keys::META_LANG;
use crate::references::configuration::keys::{EMBED_EXTERNAL, META_LANG};
use crate::references::configuration::Value;
use crate::references::templates::{Template, TemplateVariable};
use asciimath_rs::format::mathml::ToMathML;
use htmlescape::encode_attribute;
@ -103,12 +104,23 @@ impl ToHtml for Document {
.lock()
.unwrap()
.add_download(MATHJAX_URL.to_string());
downloads.lock().unwrap().download_all();
if let Some(Value::Bool(embed)) = self
.config
.get_entry(EMBED_EXTERNAL)
.map(|e| e.get().clone())
{
if embed {
downloads.lock().unwrap().download_all();
}
} else {
downloads.lock().unwrap().download_all();
}
let path = if let Some(path) = &self.path {
format!("path=\"{}\"", encode_attribute(path.as_str()))
} else {
"".to_string()
};
if self.is_root {
let language = self
.config
@ -123,10 +135,16 @@ 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)?;
@ -139,6 +157,10 @@ impl ToHtml for Document {
writer.write("<style>".to_string())?;
writer.write(minify(String::from_utf8(data).unwrap().as_str()))?;
writer.write("</style>".to_string())?;
} else {
writer.write("<link rel=\"stylsheet\" href=\"".to_string())?;
writer.write_attribute(stylesheet.path.clone())?;
writer.write("\">".to_string())?;
}
}
writer.write("</head><body><div class=\"content\">".to_string())?;

@ -58,6 +58,7 @@ impl ParserOptions {
self
}
/// If external sources should be cached when after downloaded
pub fn use_cache(self, value: bool) -> Self {
self.document.downloads.lock().unwrap().use_cache = value;

@ -5,3 +5,4 @@ pub const IMP_IGNORE: &str = "ignored-imports";
pub const IMP_STYLESHEETS: &str = "included-stylesheets";
pub const IMP_CONFIGS: &str = "included-configs";
pub const IMP_BIBLIOGRAPHY: &str = "included-bibliography";
pub const EMBED_EXTERNAL: &str = "embed-external";

Loading…
Cancel
Save