Center images when they are the only contents in a paragraph.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
use std::any::Any;
|
||||
|
||||
use super::macros::intermediate;
|
||||
use super::IObject;
|
||||
use crate::error::CustomError;
|
||||
@@ -41,4 +43,32 @@ impl IParagraph {
|
||||
post_blank,
|
||||
})
|
||||
}
|
||||
|
||||
/// Checks if the paragraph contains nothing but a single image.
|
||||
///
|
||||
/// When this happens, we want to center the image.
|
||||
pub(crate) fn is_single_image(&self) -> bool {
|
||||
let num_images = self
|
||||
.children
|
||||
.iter()
|
||||
.filter(|c| match c {
|
||||
IObject::RegularLink(iregular_link) => match &iregular_link.target {
|
||||
super::LinkTarget::Image { src, alt } => true,
|
||||
_ => false,
|
||||
},
|
||||
_ => false,
|
||||
})
|
||||
.count();
|
||||
num_images == 1
|
||||
&& self.children.iter().all(|c| match c {
|
||||
IObject::RegularLink(iregular_link) => match &iregular_link.target {
|
||||
super::LinkTarget::Image { src, alt } => true,
|
||||
_ => false,
|
||||
},
|
||||
IObject::PlainText(iplain_text) => {
|
||||
iplain_text.source.chars().all(|c| c.is_ascii_whitespace())
|
||||
}
|
||||
_ => false,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user