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]] [[package]]
name = "snekdown" name = "snekdown"
version = "0.22.0" version = "0.22.1"
dependencies = [ dependencies = [
"asciimath-rs 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "base64 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)",

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

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

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

Loading…
Cancel
Save