This commit is contained in:
@ -19,9 +19,15 @@ pub fn generate_picture_markup(
|
||||
width: u32,
|
||||
height: u32,
|
||||
alt_text: &str,
|
||||
class_name: Option<&str>,
|
||||
generate_image: bool,
|
||||
) -> Result<String, anyhow::Error> {
|
||||
let exported_formats = get_export_formats(orig_img_path);
|
||||
let class_attr = if let Some(class) = class_name {
|
||||
format!(r#"class="{class}""#)
|
||||
} else {
|
||||
"".to_string()
|
||||
};
|
||||
|
||||
if exported_formats.is_empty() {
|
||||
return Ok(formatdoc!(
|
||||
@ -29,6 +35,7 @@ pub fn generate_picture_markup(
|
||||
src="{orig_img_path}"
|
||||
width="{width}"
|
||||
height="{height}"
|
||||
{class_attr}
|
||||
alt="{alt_text}"
|
||||
>"#
|
||||
));
|
||||
@ -99,6 +106,7 @@ pub fn generate_picture_markup(
|
||||
width="{width}"
|
||||
height="{height}"
|
||||
alt="{alt_text}"
|
||||
{class_attr}
|
||||
>"#
|
||||
);
|
||||
|
||||
@ -307,8 +315,15 @@ fn test_generate_picture_markup() {
|
||||
</picture>"#,
|
||||
};
|
||||
assert_eq!(
|
||||
generate_picture_markup(orig_img_path, width, height, "Testing image alt", false)
|
||||
.expect("picture markup has to be generated"),
|
||||
generate_picture_markup(
|
||||
orig_img_path,
|
||||
width,
|
||||
height,
|
||||
"Testing image alt",
|
||||
None,
|
||||
false
|
||||
)
|
||||
.expect("picture markup has to be generated"),
|
||||
result
|
||||
);
|
||||
}
|
||||
|
@ -125,17 +125,23 @@ pub fn parse_html(markdown: &str, generate_images: bool) -> String {
|
||||
);
|
||||
|
||||
// Place image into the content with scaled reso to a boundary
|
||||
let picture_markup =
|
||||
generate_picture_markup(&dest_url, max_width, max_height, &title, generate_images)
|
||||
.unwrap_or(formatdoc!(
|
||||
r#"
|
||||
let picture_markup = generate_picture_markup(
|
||||
&dest_url,
|
||||
max_width,
|
||||
max_height,
|
||||
&title,
|
||||
None,
|
||||
generate_images,
|
||||
)
|
||||
.unwrap_or(formatdoc!(
|
||||
r#"
|
||||
<img
|
||||
alt="{alt}"
|
||||
src="{src}"
|
||||
/>"#,
|
||||
alt = title,
|
||||
src = dest_url,
|
||||
));
|
||||
alt = title,
|
||||
src = dest_url,
|
||||
));
|
||||
debug!(
|
||||
"Image link_type: {:?} url: {} title: {} id: {}",
|
||||
link_type, dest_url, title, id
|
||||
|
Reference in New Issue
Block a user