Center images when they are the only contents in a paragraph.
This commit is contained in:
parent
c371b999d5
commit
ae6f18d19c
@ -9,8 +9,9 @@
|
||||
|
||||
--blog-post-background-color: #0a0a0a;
|
||||
|
||||
--src-font-family: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo,
|
||||
Consolas, "DejaVu Sans Mono", monospace;
|
||||
--src-font-family:
|
||||
ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas,
|
||||
"DejaVu Sans Mono", monospace;
|
||||
|
||||
--src-block-background-color: #141414;
|
||||
--src-block-border-color: #84828f;
|
||||
@ -55,8 +56,9 @@
|
||||
body {
|
||||
color: var(--site-text-color);
|
||||
background-color: var(--site-background-color);
|
||||
font-family: source-sans-pro, Seravek, "Gill Sans Nova", Ubuntu, Calibri,
|
||||
"DejaVu Sans", sans-serif;
|
||||
font-family:
|
||||
source-sans-pro, Seravek, "Gill Sans Nova", Ubuntu, Calibri, "DejaVu Sans",
|
||||
sans-serif;
|
||||
|
||||
a:link,
|
||||
a:visited {
|
||||
@ -146,6 +148,10 @@ body {
|
||||
|
||||
p {
|
||||
margin: 1rem 0;
|
||||
|
||||
&.image {
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
.src_block {
|
||||
|
@ -1,3 +1,3 @@
|
||||
<p>{#.children}
|
||||
<p class="{?.is_single_image}image{/.is_single_image}">{#.children}
|
||||
{>object/}
|
||||
{/.children}</p>
|
||||
|
@ -12,6 +12,7 @@ use super::RenderObject;
|
||||
#[serde(rename = "paragraph")]
|
||||
pub(crate) struct RenderParagraph {
|
||||
children: Vec<RenderObject>,
|
||||
is_single_image: bool,
|
||||
post_blank: organic::types::PostBlank,
|
||||
}
|
||||
|
||||
@ -26,6 +27,7 @@ render!(RenderParagraph, IParagraph, original, render_context, {
|
||||
|
||||
Ok(RenderParagraph {
|
||||
children,
|
||||
is_single_image: original.is_single_image(),
|
||||
post_blank: original.post_blank,
|
||||
})
|
||||
});
|
||||
|
@ -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,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user