Fix image description and paths

feature/epub-rendering
trivernis 4 years ago
parent 4d27e054da
commit 8fe2c47739

2
Cargo.lock generated

@ -1117,7 +1117,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "snekdown"
version = "0.22.0"
version = "0.22.1"
dependencies = [
"asciimath-rs 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"base64 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)",

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

@ -363,23 +363,22 @@ impl ToHtml for Image {
}
}
if let Some(description) = self.url.description.clone() {
let description = description
.iter()
.fold("".to_string(), |a, b| format!("{}&#32;{}", a, b.to_html()));
minify(
format!(
"<div class='figure'>\
<a href={0}>\
<img src='{1}' alt='{2}' style='{3}'/>\
<a href={}>\
<img src='{}' alt='{}' style='{}'/>\
</a>\
<label class='imageDescription'>{2}</label>\
<label class='imageDescription'>{}</label>\
</div>",
encode_attribute(self.url.url.as_str()),
url,
encode_attribute(
description
.iter()
.fold("".to_string(), |a, b| format!("{}{}", a, b.to_html()))
.as_str()
),
style
encode_attribute(description.as_str()),
style,
description
)
.as_str(),
)

@ -7,6 +7,7 @@ use crate::references::configuration::keys::BIB_REF_DISPLAY;
use crate::references::templates::{GetTemplateVariables, Template, TemplateVariable};
use crate::Parser;
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::{Arc, RwLock};
pub(crate) trait ParseInline {
@ -140,11 +141,15 @@ impl ParseInline for Parser {
self.ctm.seek_one()?;
self.ctm.seek_any(&INLINE_WHITESPACE)?;
let url = self
let mut url = self
.ctm
.get_string_until_any_or_rewind(&[URL_CLOSE], &[LB], start_index)?;
self.ctm.seek_one()?;
let url_path = PathBuf::from(url.clone());
if url_path.exists() {
url = self.transform_path(url).to_str().unwrap().to_string()
}
if description.len() > 0 {
Ok(Url::new(Some(description), url))

Loading…
Cancel
Save