This commit is contained in:
parent
73c28e5e76
commit
8bf1be32fe
1 changed files with 43 additions and 36 deletions
|
@ -230,46 +230,53 @@ fn fix_images_and_integration(path: &str, html: &str) -> (String, Metadata) {
|
||||||
mail_obfsucated: false,
|
mail_obfsucated: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
(
|
// Collection of any additional metadata
|
||||||
rewrite_str(
|
let mut additional_metadata = Vec::new();
|
||||||
html,
|
|
||||||
RewriteStrSettings {
|
|
||||||
element_content_handlers: vec![element!("img", |el| {
|
|
||||||
if let Some(src) = el.get_attribute("src") {
|
|
||||||
let img_src = Path::new(path).parent().unwrap();
|
|
||||||
let img_path = urlencoding::decode(img_src.join(src).to_str().unwrap())
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
if let Ok(file) = fs::read_to_string(&img_path) {
|
|
||||||
let mime = mime_guess::from_path(&img_path).first_or_octet_stream();
|
|
||||||
if mime == "text/markdown" {
|
|
||||||
let mut options = get_options();
|
|
||||||
options.extension.footnotes = false;
|
|
||||||
let data = read_md(
|
|
||||||
&img_path,
|
|
||||||
&file,
|
|
||||||
&TypeFileMetadata::Generic,
|
|
||||||
Some(options),
|
|
||||||
);
|
|
||||||
el.replace(&data.content, ContentType::Html);
|
|
||||||
metadata.merge(&data.metadata);
|
|
||||||
} else {
|
|
||||||
let image = general_purpose::STANDARD.encode(file);
|
|
||||||
|
|
||||||
el.set_attribute("src", &format!("data:{mime};base64,{image}"))
|
let result = rewrite_str(
|
||||||
.unwrap();
|
html,
|
||||||
}
|
RewriteStrSettings {
|
||||||
|
element_content_handlers: vec![element!("img", |el| {
|
||||||
|
if let Some(src) = el.get_attribute("src") {
|
||||||
|
let img_src = Path::new(path).parent().unwrap();
|
||||||
|
let img_path = urlencoding::decode(img_src.join(src).to_str().unwrap())
|
||||||
|
.unwrap()
|
||||||
|
.to_string();
|
||||||
|
if let Ok(file) = fs::read_to_string(&img_path) {
|
||||||
|
let mime = mime_guess::from_path(&img_path).first_or_octet_stream();
|
||||||
|
if mime == "text/markdown" {
|
||||||
|
let mut options = get_options();
|
||||||
|
options.extension.footnotes = false;
|
||||||
|
let data = read_md(
|
||||||
|
&img_path,
|
||||||
|
&file,
|
||||||
|
&TypeFileMetadata::Generic,
|
||||||
|
Some(options),
|
||||||
|
);
|
||||||
|
el.replace(&data.content, ContentType::Html);
|
||||||
|
|
||||||
|
// Store the metadata for later merging
|
||||||
|
additional_metadata.push(data.metadata);
|
||||||
|
} else {
|
||||||
|
let image = general_purpose::STANDARD.encode(file);
|
||||||
|
el.set_attribute("src", &format!("data:{mime};base64,{image}"))
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
})],
|
})],
|
||||||
..RewriteStrSettings::default()
|
..RewriteStrSettings::default()
|
||||||
},
|
},
|
||||||
)
|
|
||||||
.unwrap(),
|
|
||||||
metadata,
|
|
||||||
)
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
// Merge all collected metadata
|
||||||
|
for additional in additional_metadata {
|
||||||
|
metadata.merge(&additional);
|
||||||
|
}
|
||||||
|
|
||||||
|
(result, metadata)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Transform markdown string to File structure
|
/// Transform markdown string to File structure
|
||||||
|
|
Loading…
Reference in a new issue