Basic cours support #44
1 changed files with 11 additions and 6 deletions
|
@ -205,11 +205,16 @@ fn fix_local_img(path: &str, html: String) -> String {
|
||||||
if let Some(img_src) = Path::new(path).parent() {
|
if let Some(img_src) = Path::new(path).parent() {
|
||||||
let img_path = img_src.join(src);
|
let img_path = img_src.join(src);
|
||||||
let file = fs::read_to_string(&img_path).unwrap();
|
let file = fs::read_to_string(&img_path).unwrap();
|
||||||
let encoded = general_purpose::STANDARD.encode(file);
|
let image = general_purpose::STANDARD.encode(file);
|
||||||
let mime_type = mime_guess::from_path(img_path)
|
|
||||||
.first_or_octet_stream()
|
el.set_attribute(
|
||||||
.to_string();
|
"src",
|
||||||
el.set_attribute("src", &format!("data:{};base64,{}", mime_type, encoded))
|
&format!(
|
||||||
|
"data:{};base64,{}",
|
||||||
|
mime_guess::from_path(img_path).first_or_octet_stream(),
|
||||||
|
image
|
||||||
|
),
|
||||||
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue