From 98f64270f36bc73f250e63ea577753354d63c478 Mon Sep 17 00:00:00 2001 From: trivernis Date: Sun, 6 Sep 2020 15:30:41 +0200 Subject: [PATCH] Update bibliographix and add bib error messages Signed-off-by: trivernis --- Cargo.lock | 8 ++++---- Cargo.toml | 4 ++-- src/format/html/to_html.rs | 15 ++++++++++++++- src/parser/line.rs | 32 ++++++++++++++++++++++---------- src/parser/mod.rs | 2 +- src/utils/downloads.rs | 8 +++----- 6 files changed, 46 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 09e4748..3f49985 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -54,7 +54,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "bibliographix" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "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]] name = "snekdown" -version = "0.26.5" +version = "0.26.6" 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)", - "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)", "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)", @@ -1680,7 +1680,7 @@ dependencies = [ "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 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 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" diff --git a/Cargo.toml b/Cargo.toml index 3dd9160..5fdab17 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snekdown" -version = "0.26.5" +version = "0.26.6" authors = ["trivernis "] edition = "2018" license-file = "LICENSE" @@ -19,7 +19,7 @@ path = "src/main.rs" [dependencies] charred = "0.3.3" asciimath-rs = "0.5.7" -bibliographix = "0.4.0" +bibliographix = "0.5.0" crossbeam-utils = "0.7.2" structopt = "0.3.14" minify = "1.1.1" diff --git a/src/format/html/to_html.rs b/src/format/html/to_html.rs index eebc6f6..c08c5e8 100644 --- a/src/format/html/to_html.rs +++ b/src/format/html/to_html.rs @@ -12,6 +12,8 @@ use syntect::highlighting::ThemeSet; use syntect::html::highlighted_html_for_string; use syntect::parsing::SyntaxSet; +const MATHJAX_URL: &str = "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"; + pub trait ToHtml { fn to_html(&self, writer: &mut HTMLWriter) -> io::Result<()>; } @@ -97,6 +99,10 @@ 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()); downloads.lock().unwrap().download_all(); let path = if let Some(path) = &self.path { format!("path=\"{}\"", encode_attribute(path.as_str())) @@ -116,7 +122,12 @@ impl ToHtml for Document { writer.write("\">".to_string())?; - writer.write("".to_string())?; + writer.write("".to_string())?; + if let Some(data) = std::mem::replace(&mut mathjax.lock().unwrap().data, None) { + writer.write("".to_string())?; + } writer.write("".to_string())?; @@ -500,6 +511,8 @@ impl ToHtml for Placeholder { if let Some(value) = &self.value { value.to_html(writer) } else { + log::debug!("Unknown placeholder [[{}]]", self.name.clone()); + writer.write_escaped(format!("[[{}]]", self.name.clone()))?; writer.write("".to_string()) diff --git a/src/parser/line.rs b/src/parser/line.rs index a9dbeca..5c52a56 100644 --- a/src/parser/line.rs +++ b/src/parser/line.rs @@ -202,11 +202,17 @@ impl ParseLine for Parser { let mut string_map = meta.get_string_map(); string_map.insert(K_KEY.to_string(), key.clone()); - if let Some(entry) = BibliographyEntry::from_hash_map(&string_map) { - *entry - } else { - eprintln!("Failed to parse bib entry with key {}", key); - return Err(self.ctm.rewind_with_error(start_index)); + match BibliographyEntry::from_hash_map(&string_map) { + Ok(entry) => *entry, + Err(msg) => { + 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)); + } } } else { let url = self @@ -217,11 +223,17 @@ impl ParseLine for Parser { map.insert(K_URL.to_string(), url); map.insert(K_KEY.to_string(), key.clone()); - if let Some(entry) = BibliographyEntry::from_hash_map(&map) { - *entry - } else { - eprintln!("Failed to parse bib entry with key {}", key); - return Err(self.ctm.rewind_with_error(start_index)); + match BibliographyEntry::from_hash_map(&map) { + Ok(entry) => *entry, + Err(msg) => { + 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)); + } } }; diff --git a/src/parser/mod.rs b/src/parser/mod.rs index bbf74ff..b21e36e 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -210,7 +210,7 @@ impl Parser { let mut paths = self.paths.lock().unwrap(); if paths.iter().find(|item| **item == path) != None { log::warn!( - "Import of \"{}\" failed: Cyclic import.\n\t--> {}\n", + "Import of \"{}\" failed: Already imported.\n\t--> {}\n", path.to_str().unwrap(), self.get_position_string(), ); diff --git a/src/utils/downloads.rs b/src/utils/downloads.rs index 2a4da25..dcc764c 100644 --- a/src/utils/downloads.rs +++ b/src/utils/downloads.rs @@ -1,4 +1,4 @@ -use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; +use indicatif::{ProgressBar, ProgressStyle}; use rayon::prelude::*; use std::fs::read; use std::path::PathBuf; @@ -32,7 +32,7 @@ impl DownloadManager { let pb = Arc::new(Mutex::new(ProgressBar::new(self.downloads.len() as u64))); pb.lock().unwrap().set_style( ProgressStyle::default_bar() - .template("Reading Imports: [{bar:40.cyan/blue}]") + .template("Fetching Embeds: [{bar:40.cyan/blue}]") .progress_chars("=> "), ); let pb_cloned = Arc::clone(&pb); @@ -41,9 +41,7 @@ impl DownloadManager { d.lock().unwrap().download(); pb.lock().unwrap().inc(1); }); - pb.lock() - .unwrap() - .finish_with_message("All downloads finished!"); + pb.lock().unwrap().finish_and_clear(); } }