Change url to allow inline formatting for description

feature/epub-rendering
trivernis 4 years ago
parent 108bcb26d5
commit 47e6490203

2
Cargo.lock generated

@ -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)",

@ -1,6 +1,6 @@
[package]
name = "snekdown"
version = "0.18.1"
version = "0.18.2"
authors = ["trivernis <trivernis@protonmail.com>"]
edition = "2018"
license-file = "LICENSE"

@ -210,7 +210,7 @@ pub struct Checkbox {
#[derive(Clone, Debug)]
pub struct Url {
pub description: Option<String>,
pub description: Option<Vec<Inline>>,
pub url: String,
}
@ -528,7 +528,7 @@ impl Row {
}
impl Url {
pub fn new(description: Option<String>, url: String) -> Self {
pub fn new(description: Option<Vec<Inline>>, url: String) -> Self {
Self { description, url }
}
}

@ -319,7 +319,12 @@ impl ToHtml for Image {
<label class='imageDescription'>{1}</label>\
</div>",
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!(
"<a href='{}'>{}</a>",
self.url.clone(),
encode_minimal(description.as_str())
description
.iter()
.fold("".to_string(), |a, b| format!("{}{}", a, b.to_html()))
.as_str()
)
} else {
format!(
"<a href='{}'>{}</a>",
self.url.clone(),
encode_attribute(self.url.clone().as_str()),
encode_minimal(self.url.clone().as_str())
)
}

@ -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))
}
}

Loading…
Cancel
Save