Update bibliographix and add bib error messages

Signed-off-by: trivernis <trivernis@protonmail.com>
feature/epub-rendering v0.27.0
trivernis 4 years ago
parent a226001b1c
commit 98f64270f3
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

8
Cargo.lock generated

@ -54,7 +54,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "bibliographix" name = "bibliographix"
version = "0.4.0" version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"chrono 0.4.15 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.15 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1204,11 +1204,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "snekdown" name = "snekdown"
version = "0.26.5" version = "0.26.6"
dependencies = [ dependencies = [
"asciimath-rs 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "base64 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)",
"bibliographix 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "bibliographix 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"charred 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "charred 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.15 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.15 (registry+https://github.com/rust-lang/crates.io-index)",
"colored 1.9.3 (registry+https://github.com/rust-lang/crates.io-index)", "colored 1.9.3 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1680,7 +1680,7 @@ dependencies = [
"checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" "checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
"checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" "checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
"checksum base64 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" "checksum base64 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff"
"checksum bibliographix 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a2a4e7a8fa9104c899346763b98d489704d1e00a95d2c3cc8b34d179ee350a35" "checksum bibliographix 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "39034545c510b822e3e5bd76147f869bae617d52961add6313ad0696084585c1"
"checksum bincode 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f30d3a39baa26f9651f17b375061f3233dde33424a8b72b0dbe93a68a0bc896d" "checksum bincode 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f30d3a39baa26f9651f17b375061f3233dde33424a8b72b0dbe93a68a0bc896d"
"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
"checksum bumpalo 3.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820" "checksum bumpalo 3.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820"

@ -1,6 +1,6 @@
[package] [package]
name = "snekdown" name = "snekdown"
version = "0.26.5" version = "0.26.6"
authors = ["trivernis <trivernis@protonmail.com>"] authors = ["trivernis <trivernis@protonmail.com>"]
edition = "2018" edition = "2018"
license-file = "LICENSE" license-file = "LICENSE"
@ -19,7 +19,7 @@ path = "src/main.rs"
[dependencies] [dependencies]
charred = "0.3.3" charred = "0.3.3"
asciimath-rs = "0.5.7" asciimath-rs = "0.5.7"
bibliographix = "0.4.0" bibliographix = "0.5.0"
crossbeam-utils = "0.7.2" crossbeam-utils = "0.7.2"
structopt = "0.3.14" structopt = "0.3.14"
minify = "1.1.1" minify = "1.1.1"

@ -12,6 +12,8 @@ use syntect::highlighting::ThemeSet;
use syntect::html::highlighted_html_for_string; use syntect::html::highlighted_html_for_string;
use syntect::parsing::SyntaxSet; use syntect::parsing::SyntaxSet;
const MATHJAX_URL: &str = "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js";
pub trait ToHtml { pub trait ToHtml {
fn to_html(&self, writer: &mut HTMLWriter) -> io::Result<()>; fn to_html(&self, writer: &mut HTMLWriter) -> io::Result<()>;
} }
@ -97,6 +99,10 @@ impl ToHtml for MetadataValue {
impl ToHtml for Document { impl ToHtml for Document {
fn to_html(&self, writer: &mut HTMLWriter) -> io::Result<()> { fn to_html(&self, writer: &mut HTMLWriter) -> io::Result<()> {
let downloads = Arc::clone(&self.downloads); let downloads = Arc::clone(&self.downloads);
let mathjax = downloads
.lock()
.unwrap()
.add_download(MATHJAX_URL.to_string());
downloads.lock().unwrap().download_all(); downloads.lock().unwrap().download_all();
let path = if let Some(path) = &self.path { let path = if let Some(path) = &self.path {
format!("path=\"{}\"", encode_attribute(path.as_str())) format!("path=\"{}\"", encode_attribute(path.as_str()))
@ -116,7 +122,12 @@ impl ToHtml for Document {
writer.write("\"><head ".to_string())?; writer.write("\"><head ".to_string())?;
writer.write(path)?; writer.write(path)?;
writer.write("/>".to_string())?; writer.write("/>".to_string())?;
writer.write("<meta charset=\"UTF-8\"><script id=\"MathJax-script\" async src=\"https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js\"></script>".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())?;
}
writer.write("<style>".to_string())?; writer.write("<style>".to_string())?;
writer.write(style)?; writer.write(style)?;
writer.write("</style>".to_string())?; writer.write("</style>".to_string())?;
@ -500,6 +511,8 @@ impl ToHtml for Placeholder {
if let Some(value) = &self.value { if let Some(value) = &self.value {
value.to_html(writer) value.to_html(writer)
} else { } else {
log::debug!("Unknown placeholder [[{}]]", self.name.clone());
writer.write_escaped(format!("[[{}]]", self.name.clone()))?;
writer.write("<!--Unknown placeholder \"".to_string())?; writer.write("<!--Unknown placeholder \"".to_string())?;
writer.write_escaped(self.name.clone())?; writer.write_escaped(self.name.clone())?;
writer.write("\"-->".to_string()) writer.write("\"-->".to_string())

@ -202,12 +202,18 @@ impl ParseLine for Parser {
let mut string_map = meta.get_string_map(); let mut string_map = meta.get_string_map();
string_map.insert(K_KEY.to_string(), key.clone()); string_map.insert(K_KEY.to_string(), key.clone());
if let Some(entry) = BibliographyEntry::from_hash_map(&string_map) { match BibliographyEntry::from_hash_map(&string_map) {
*entry Ok(entry) => *entry,
} else { Err(msg) => {
eprintln!("Failed to parse bib entry with key {}", key); log::error!(
"Failed to parse bib entry with key '{}': {}\n\t--> {}\n",
key,
msg,
self.get_position_string()
);
return Err(self.ctm.rewind_with_error(start_index)); return Err(self.ctm.rewind_with_error(start_index));
} }
}
} else { } else {
let url = self let url = self
.ctm .ctm
@ -217,12 +223,18 @@ impl ParseLine for Parser {
map.insert(K_URL.to_string(), url); map.insert(K_URL.to_string(), url);
map.insert(K_KEY.to_string(), key.clone()); map.insert(K_KEY.to_string(), key.clone());
if let Some(entry) = BibliographyEntry::from_hash_map(&map) { match BibliographyEntry::from_hash_map(&map) {
*entry Ok(entry) => *entry,
} else { Err(msg) => {
eprintln!("Failed to parse bib entry with key {}", key); log::error!(
"Failed to parse bib entry with key '{}': {}\n\t--> {}\n",
key,
msg,
self.get_position_string()
);
return Err(self.ctm.rewind_with_error(start_index)); return Err(self.ctm.rewind_with_error(start_index));
} }
}
}; };
self.document self.document

@ -210,7 +210,7 @@ impl Parser {
let mut paths = self.paths.lock().unwrap(); let mut paths = self.paths.lock().unwrap();
if paths.iter().find(|item| **item == path) != None { if paths.iter().find(|item| **item == path) != None {
log::warn!( log::warn!(
"Import of \"{}\" failed: Cyclic import.\n\t--> {}\n", "Import of \"{}\" failed: Already imported.\n\t--> {}\n",
path.to_str().unwrap(), path.to_str().unwrap(),
self.get_position_string(), self.get_position_string(),
); );

@ -1,4 +1,4 @@
use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; use indicatif::{ProgressBar, ProgressStyle};
use rayon::prelude::*; use rayon::prelude::*;
use std::fs::read; use std::fs::read;
use std::path::PathBuf; use std::path::PathBuf;
@ -32,7 +32,7 @@ impl DownloadManager {
let pb = Arc::new(Mutex::new(ProgressBar::new(self.downloads.len() as u64))); let pb = Arc::new(Mutex::new(ProgressBar::new(self.downloads.len() as u64)));
pb.lock().unwrap().set_style( pb.lock().unwrap().set_style(
ProgressStyle::default_bar() ProgressStyle::default_bar()
.template("Reading Imports: [{bar:40.cyan/blue}]") .template("Fetching Embeds: [{bar:40.cyan/blue}]")
.progress_chars("=> "), .progress_chars("=> "),
); );
let pb_cloned = Arc::clone(&pb); let pb_cloned = Arc::clone(&pb);
@ -41,9 +41,7 @@ impl DownloadManager {
d.lock().unwrap().download(); d.lock().unwrap().download();
pb.lock().unwrap().inc(1); pb.lock().unwrap().inc(1);
}); });
pb.lock() pb.lock().unwrap().finish_and_clear();
.unwrap()
.finish_with_message("All downloads finished!");
} }
} }

Loading…
Cancel
Save