natter/src/intermediate/plain_list_item.rs
Tom Alexander 397d4ea0bc
All checks were successful
rust-test Build rust-test has succeeded
rust-clippy Build rust-clippy has succeeded
build-natter Build build-natter has succeeded
format Build format has succeeded
Fix clippy issues.
2023-12-23 07:08:06 -05:00

61 lines
1.9 KiB
Rust

use super::macros::intermediate;
use super::IPlainListSimpleItem;
use super::IElement;
use super::IObject;
use crate::error::CustomError;
#[derive(Debug, Clone)]
pub(crate) struct IPlainListItem {
pub(crate) tag: Vec<IObject>,
pub(crate) children: Vec<IElement>,
}
intermediate!(
IPlainListItem,
&'orig organic::types::PlainListItem<'parse>,
original,
intermediate_context,
{
let tag = {
let mut ret = Vec::new();
for obj in original.tag.iter() {
ret.push(IObject::new(intermediate_context.clone(), obj).await?);
}
ret
};
let children = {
let mut ret = Vec::new();
// Special case for list items with only paragraphs and sublists as their children. In those cases, the paragraph tags are omitted.
let is_simple_list_item = original.children.iter().all(|child| {
matches!(
child,
organic::types::Element::Paragraph(_) | organic::types::Element::PlainList(_)
)
});
if is_simple_list_item {
for elem in original.children.iter() {
if let organic::types::Element::Paragraph(paragraph) = elem {
ret.push(IElement::PlainListSimpleItem(
IPlainListSimpleItem::new(intermediate_context.clone(), paragraph)
.await?,
));
} else {
ret.push(IElement::new(intermediate_context.clone(), elem).await?);
}
}
} else {
for elem in original.children.iter() {
ret.push(IElement::new(intermediate_context.clone(), elem).await?);
}
}
ret
};
Ok(IPlainListItem { tag, children })
}
);