diff --git a/Cargo.lock b/Cargo.lock index 34877ce..ecf4146 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -571,7 +571,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "snekdown" -version = "0.18.1" +version = "0.18.2" dependencies = [ "charred 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index aa4108f..64d98cd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snekdown" -version = "0.18.1" +version = "0.18.2" authors = ["trivernis "] edition = "2018" license-file = "LICENSE" diff --git a/src/elements/mod.rs b/src/elements/mod.rs index fea2d85..4487948 100644 --- a/src/elements/mod.rs +++ b/src/elements/mod.rs @@ -210,7 +210,7 @@ pub struct Checkbox { #[derive(Clone, Debug)] pub struct Url { - pub description: Option, + pub description: Option>, pub url: String, } @@ -528,7 +528,7 @@ impl Row { } impl Url { - pub fn new(description: Option, url: String) -> Self { + pub fn new(description: Option>, url: String) -> Self { Self { description, url } } } diff --git a/src/format/html.rs b/src/format/html.rs index b3ad830..cb835b6 100644 --- a/src/format/html.rs +++ b/src/format/html.rs @@ -319,7 +319,12 @@ impl ToHtml for Image { \ ", encode_attribute(self.url.url.clone().as_str()), - encode_attribute(description.as_str()), + encode_attribute( + description + .iter() + .fold("".to_string(), |a, b| format!("{}{}", a, b.to_html())) + .as_str() + ), style ) .as_str(), @@ -379,12 +384,15 @@ impl ToHtml for Url { format!( "{}", self.url.clone(), - encode_minimal(description.as_str()) + description + .iter() + .fold("".to_string(), |a, b| format!("{}{}", a, b.to_html())) + .as_str() ) } else { format!( "{}", - self.url.clone(), + encode_attribute(self.url.clone().as_str()), encode_minimal(self.url.clone().as_str()) ) } diff --git a/src/parser/inline.rs b/src/parser/inline.rs index 92e9880..e714bdb 100644 --- a/src/parser/inline.rs +++ b/src/parser/inline.rs @@ -113,12 +113,19 @@ impl ParseInline for Parser { let start_index = self.ctm.get_index(); self.ctm.seek_any(&INLINE_WHITESPACE)?; - let mut description = String::new(); + let mut description = Vec::new(); + if self.ctm.check_char(&DESC_OPEN) { self.ctm.seek_one()?; - description = - self.ctm - .get_string_until_any_or_rewind(&[DESC_CLOSE], &[LB], start_index)?; + self.inline_break_at.push(DESC_CLOSE); + + while let Ok(inline) = self.parse_inline() { + description.push(inline); + if self.ctm.check_char(&DESC_CLOSE) { + break; + } + } + self.inline_break_at.pop(); } else if !short_syntax { return Err(self.ctm.rewind_with_error(start_index)); } @@ -133,10 +140,10 @@ impl ParseInline for Parser { self.ctm.seek_one()?; - if description.is_empty() { - Ok(Url::new(None, url)) - } else { + if description.len() > 0 { Ok(Url::new(Some(description), url)) + } else { + Ok(Url::new(None, url)) } }