From 8cf6dd33b7fd1dfefa5543b3c6c02f33aed17ac2 Mon Sep 17 00:00:00 2001 From: trivernis Date: Thu, 21 Jan 2021 20:21:38 +0100 Subject: [PATCH 1/3] Fix escapes in monospace and progressbar Signed-off-by: trivernis --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/parser/inline.rs | 8 +++++--- src/utils/image_converting.rs | 2 +- src/utils/parsing.rs | 9 +++++++++ 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8f8c730..116c3f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -235,9 +235,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "charred" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e01302bf6a3d92a90baa965f84a735938520ab9fd896f0694a71e8dec5405ce" +checksum = "0d76bd26a00789c7e782d3ba5c0adae6f7eabc2a1026dfb41838b0e11ebf55f8" [[package]] name = "chrono" diff --git a/Cargo.toml b/Cargo.toml index 2f5ef55..7494436 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ path = "src/main.rs" pdf = ["headless_chrome", "failure"] [dependencies] -charred = "0.3.3" +charred = "0.3.4" asciimath-rs = "0.5.7" bibliographix = "0.6.0" crossbeam-utils = "0.7.2" diff --git a/src/parser/inline.rs b/src/parser/inline.rs index 2665307..aa7bcaf 100644 --- a/src/parser/inline.rs +++ b/src/parser/inline.rs @@ -6,6 +6,7 @@ use crate::parser::block::ParseBlock; use crate::references::glossary::GlossaryDisplay; use crate::references::glossary::GlossaryReference; use crate::references::templates::{GetTemplateVariables, Template, TemplateVariable}; +use crate::utils::parsing::remove_single_backlslash; use crate::Parser; use bibliographix::references::bib_reference::BibRef; use parking_lot::Mutex; @@ -295,9 +296,10 @@ impl ParseInline for Parser { let start_index = self.ctm.get_index(); self.ctm.assert_char(&BACKTICK, Some(start_index))?; self.ctm.seek_one()?; - let content = self - .ctm - .get_string_until_any_or_rewind(&[BACKTICK, LB], &[], start_index)?; + let mut content = + self.ctm + .get_string_until_any_or_rewind(&[BACKTICK, LB], &[], start_index)?; + content = remove_single_backlslash(content); self.ctm.assert_char(&BACKTICK, Some(start_index))?; self.ctm.seek_one()?; diff --git a/src/utils/image_converting.rs b/src/utils/image_converting.rs index 3f8a526..5cab906 100644 --- a/src/utils/image_converting.rs +++ b/src/utils/image_converting.rs @@ -60,7 +60,7 @@ impl ImageConverter { } pb.lock().tick(); }); - pb.lock().finish(); + pb.lock().finish_and_clear(); } } diff --git a/src/utils/parsing.rs b/src/utils/parsing.rs index d89de44..823ff74 100644 --- a/src/utils/parsing.rs +++ b/src/utils/parsing.rs @@ -1,6 +1,15 @@ +use regex::Regex; #[macro_export] macro_rules! parse { ($str:expr) => { Parser::new($str.to_string(), None).parse() }; } + +/// Removes a single backslash from the given content +pub(crate) fn remove_single_backlslash(content: S) -> String { + let content = content.to_string(); + lazy_static::lazy_static! {static ref R: Regex = Regex::new(r"\\(?P[^\\])").unwrap();} + + R.replace_all(&*content, "$c").to_string() +} From e99b80ecf04e6fa949f6cead82f869fb7cbe1ee7 Mon Sep 17 00:00:00 2001 From: trivernis Date: Thu, 21 Jan 2021 20:32:44 +0100 Subject: [PATCH 2/3] Fix block documents being ignored at EOF Fixes that block elements are being ignored when written as the last element of a file (Fixes #14)x Signed-off-by: trivernis --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/parser/block.rs | 7 +++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 116c3f0..97d48c6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -235,9 +235,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "charred" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d76bd26a00789c7e782d3ba5c0adae6f7eabc2a1026dfb41838b0e11ebf55f8" +checksum = "ed9759715d56a062d5636cd0cbc71f2aa8a978afe08c572a69e65e8cf53418f5" [[package]] name = "chrono" diff --git a/Cargo.toml b/Cargo.toml index 7494436..bb3649f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ path = "src/main.rs" pdf = ["headless_chrome", "failure"] [dependencies] -charred = "0.3.4" +charred = "0.3.5" asciimath-rs = "0.5.7" bibliographix = "0.6.0" crossbeam-utils = "0.7.2" diff --git a/src/parser/block.rs b/src/parser/block.rs index c2c5a40..6ed9576 100644 --- a/src/parser/block.rs +++ b/src/parser/block.rs @@ -135,8 +135,9 @@ impl ParseBlock for Parser { let language = self.ctm.get_string_until_any(&[LB], &[])?; self.ctm.seek_one()?; let text = self.ctm.get_string_until_sequence(&[&SQ_CODE_BLOCK], &[])?; + for _ in 0..2 { - self.ctm.seek_one()?; + self.ctm.try_seek(); } Ok(CodeBlock { @@ -153,7 +154,7 @@ impl ParseBlock for Parser { self.ctm.seek_one()?; let text = self.ctm.get_string_until_sequence(&[SQ_MATH], &[])?; for _ in 0..1 { - self.ctm.seek_one()?; + self.ctm.try_seek(); } Ok(MathBlock { expression: asciimath_rs::parse(text), @@ -231,6 +232,7 @@ impl ParseBlock for Parser { let ordered = self.ctm.get_current().is_numeric(); list.ordered = ordered; let mut list_hierarchy: Vec = Vec::new(); + while let Ok(mut item) = self.parse_list_item() { while let Some(parent_item) = list_hierarchy.pop() { if parent_item.level < item.level { @@ -289,6 +291,7 @@ impl ParseBlock for Parser { } let seek_index = self.ctm.get_index(); let mut table = Table::new(header); + while let Ok(_) = self.ctm.seek_one() { self.ctm.seek_any(&INLINE_WHITESPACE)?; if !self.ctm.check_any(&[MINUS, PIPE]) || self.ctm.check_char(&LB) { From cac1cbe8d658b8a7eee58a03df944100774425d3 Mon Sep 17 00:00:00 2001 From: trivernis Date: Thu, 21 Jan 2021 20:37:12 +0100 Subject: [PATCH 3/3] Bump version Signed-off-by: trivernis --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 97d48c6..b5964e6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2315,7 +2315,7 @@ checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" [[package]] name = "snekdown" -version = "0.32.1" +version = "0.32.2" dependencies = [ "asciimath-rs", "base64 0.12.3", diff --git a/Cargo.toml b/Cargo.toml index bb3649f..4190ed1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snekdown" -version = "0.32.1" +version = "0.32.2" authors = ["trivernis "] edition = "2018" license-file = "LICENSE"