Fix checkboxes, escapes and inline math

- Fix empty checkboxes not being displayed when line starts with them
- Fix inline math consunming following char
- Fix single escape characters being displayed
feature/epub-rendering
trivernis 4 years ago
parent b81f9f03d6
commit 1af43f4ff0

16
Cargo.lock generated

@ -26,7 +26,7 @@ name = "asciimath-rs"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"charred 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"charred 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"htmlescape 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"maplit 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -83,12 +83,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "charred"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "charred"
version = "0.3.0"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@ -599,10 +594,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "snekdown"
version = "0.19.3"
version = "0.19.4"
dependencies = [
"asciimath-rs 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"charred 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"charred 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)",
"colored 1.9.3 (registry+https://github.com/rust-lang/crates.io-index)",
"crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -817,8 +812,7 @@ dependencies = [
"checksum byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
"checksum cc 1.0.58 (registry+https://github.com/rust-lang/crates.io-index)" = "f9a06fb2e53271d7c279ec1efea6ab691c35a2ae67ec0d91d7acec0caf13b518"
"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
"checksum charred 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8cf73c7fbbaf59d5643f99c6a4413eba1b914a7489c39b730ec7d8d72e7bb061"
"checksum charred 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "81443b6f18b18560f94a0e14d529a1db379581473217b1b2a40ecae0c96a5d0e"
"checksum charred 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e098f81a798d5019ee7b85efe9aa93dd48d4ea16fd1965f7afa24db6a1900652"
"checksum chrono 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)" = "c74d84029116787153e02106bf53e66828452a4b325cc8652b788b5967c0a0b6"
"checksum clap 2.33.2 (registry+https://github.com/rust-lang/crates.io-index)" = "10040cdf04294b565d9e0319955430099ec3813a64c952b86a41200ad714ae48"
"checksum colored 1.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f4ffc801dacf156c5854b9df4f425a626539c3a6ef7893cc0c5084a23f0b6c59"

@ -1,6 +1,6 @@
[package]
name = "snekdown"
version = "0.19.3"
version = "0.19.4"
authors = ["trivernis <trivernis@protonmail.com>"]
edition = "2018"
license-file = "LICENSE"
@ -17,7 +17,7 @@ name = "snekdown"
path = "src/main.rs"
[dependencies]
charred = "0.2.2"
charred = "0.3.1"
crossbeam-utils = "0.7.2"
structopt = "0.3.14"
minify = "1.1.1"

@ -169,6 +169,7 @@ pub enum Inline {
Math(Math),
BibReference(Arc<RwLock<BibReference>>),
TemplateVar(Arc<RwLock<TemplateVariable>>),
LineBreak,
}
#[derive(Clone, Debug)]

@ -66,6 +66,7 @@ impl ToHtml for Inline {
Inline::BibReference(bibref) => bibref.read().unwrap().to_html(),
Inline::TemplateVar(var) => var.read().unwrap().to_html(),
Inline::Math(m) => m.to_html(),
Inline::LineBreak => "<br>".to_string(),
}
}
}

@ -95,7 +95,6 @@ impl ParseInline for Parser {
/// parses an image url
fn parse_image(&mut self) -> ParseResult<Image> {
let start_index = self.ctm.get_index();
self.ctm.seek_any(&INLINE_WHITESPACE)?;
self.ctm.assert_char(&IMG_START, Some(start_index))?;
self.ctm.seek_one()?;
@ -114,8 +113,6 @@ impl ParseInline for Parser {
// parses an url
fn parse_url(&mut self, short_syntax: bool) -> ParseResult<Url> {
let start_index = self.ctm.get_index();
self.ctm.seek_any(&INLINE_WHITESPACE)?;
let mut description = Vec::new();
if self.ctm.check_char(&DESC_OPEN) {
@ -329,7 +326,10 @@ impl ParseInline for Parser {
return Err(self.ctm.err());
}
let mut characters = String::new();
if !self.ctm.check_char(&SPECIAL_ESCAPE) {
characters.push(self.ctm.get_current());
}
while let Some(ch) = self.ctm.next_char() {
if self.ctm.check_any(&INLINE_SPECIAL_CHARS)
|| self.ctm.check_any(&self.inline_break_at)
@ -337,8 +337,10 @@ impl ParseInline for Parser {
{
break;
}
if !self.ctm.check_char(&SPECIAL_ESCAPE) {
characters.push(ch)
}
}
if characters.len() > 0 {
Ok(PlainText { value: characters })

@ -1,6 +1,6 @@
use super::ParseResult;
use crate::elements::tokens::*;
use crate::elements::{Cell, Centered, Header, Line, ListItem, Row, Ruler, TextLine};
use crate::elements::{Cell, Centered, Header, Inline, Line, ListItem, Row, Ruler, TextLine};
use crate::parser::inline::ParseInline;
use crate::references::bibliography::BibEntry;
use crate::Parser;
@ -155,9 +155,12 @@ impl ParseLine for Parser {
if self.ctm.check_char(&LB) {
self.ctm.seek_one()?;
if self.ctm.check_char(&LB) {
text.add_subtext(Inline::LineBreak)
}
}
if text.subtext.len() > 0 || !self.ctm.check_eof() {
if text.subtext.len() > 0 {
Ok(text)
} else {
Err(self.ctm.err())

Loading…
Cancel
Save