make alt text optional in image macro

This commit is contained in:
Crispy 2024-08-29 21:47:55 +02:00
parent 21c681fc8a
commit eafbc710ff

View file

@ -44,7 +44,9 @@ pub fn convert_document(markdown: &str) -> String {
} }
if let Some(img_info) = line.strip_prefix("==image:") { if let Some(img_info) = line.strip_prefix("==image:") {
let (src, alt) = img_info.split_once(':').unwrap(); let mut attributes = img_info.split(':');
let src = attributes.next().unwrap();
let alt = attributes.next().unwrap_or_else(|| &"\"\"");
html += &format!("<img loading=\"lazy\" src={src} alt={alt} title={alt}></img>\n"); html += &format!("<img loading=\"lazy\" src={src} alt={alt} title={alt}></img>\n");
continue; continue;
} }